rspec-abq 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29210d070dba423ba2bb9aad82deb1df9e4a4fb01e70bec05b1d728d20e29d5e
4
- data.tar.gz: 1771fe5b152192dd256b29cc412526fc275c381c1c697cec4a51b6ae5a4b0174
3
+ metadata.gz: 03b2ac40b5bb4d24a54abbaeb06c9e3705641cc27b5c247aa86972bf04095af4
4
+ data.tar.gz: 4d3095d28da6d63731dcd0a64c1c8968033f02155cf0755230e0ebc50854db57
5
5
  SHA512:
6
- metadata.gz: 8f89f037b50d88458b443c534ec78e20d9bbf4661d81cf68774f2bd7438a588cace8a991dfe101d1a4424a98956e186ba20f65d51f47d837ff5237dbf4b00a4f
7
- data.tar.gz: 22bf4931dc4ee3639334e1e91451e0577591c215ad279802560d8ae7256b56a31a93fcb495b932f9e490658aa2e1bc23e1100c29ed735b0515312f1e9dae2c6f
6
+ metadata.gz: 84005f5d7672dcbc96152d183fe5597f3da8da8d29ed88dc9c83ef5dbd6a70bda68c74589aa24e5e7bb191b43f156760cf4a095457a6059ba19adefe1fa86480
7
+ data.tar.gz: 493eb56209f8bc6049883a67122fb1ddc55818d7ef326d8d46cd8d40525a4c8003b92b897d36b10d3e3cc11a13112b0cfce9b50f3a63b36e21115be9eca1044f
@@ -1,6 +1,6 @@
1
1
  module RSpec
2
2
  module Abq
3
3
  # current version!
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
  end
6
6
  end
data/lib/rspec/abq.rb CHANGED
@@ -148,8 +148,20 @@ module RSpec
148
148
  Extensions.setup!
149
149
  end
150
150
 
151
+ # Base ABQ error.
152
+ Error = Class.new(StandardError)
153
+
151
154
  # raised when check_configuration fails
152
- UnsupportedConfigurationError = Class.new(StandardError)
155
+ UnsupportedConfigurationError = Class.new(Error)
156
+
157
+ # Failed to connect and initialize handshake.
158
+ ConnectionFailed = Class.new(Error)
159
+
160
+ # Communication between abq sockets follows the following protocol:
161
+ # - The first 4 bytes an unsigned 32-bit integer (big-endian) representing
162
+ # the size of the rest of the message.
163
+ # - The rest of the message is a JSON-encoded payload.
164
+ ConnectionBroken = Class.new(Error)
153
165
 
154
166
  # raises if RSpec is configured in a way that's incompatible with rspec-abq
155
167
  def self.check_configuration!(config)
@@ -214,12 +226,16 @@ module RSpec
214
226
 
215
227
  # Creates the socket to communicate with the worker and sends the worker the protocol
216
228
  # @!visibility private
217
- def self.socket
218
- @socket ||= TCPSocket.new(*ENV[ABQ_SOCKET].split(":")).tap do |socket|
219
- # Messages sent to/received from the ABQ worker should be done so ASAP.
220
- # Since we're on a local network, we don't care about packet reduction here.
221
- socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
222
- protocol_write(NATIVE_RUNNER_SPAWNED_MESSAGE, socket)
229
+ def self.socket(connect_timeout: 5)
230
+ @socket ||= begin
231
+ Socket.tcp(*ENV[ABQ_SOCKET].split(":"), connect_timeout: connect_timeout).tap do |socket|
232
+ # Messages sent to/received from the ABQ worker should be done so ASAP.
233
+ # Since we're on a local network, we don't care about packet reduction here.
234
+ socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
235
+ protocol_write(NATIVE_RUNNER_SPAWNED_MESSAGE, socket)
236
+ end
237
+ rescue
238
+ raise ConnectionFailed, "Unable to connect to ABQ socket #{ENV[ABQ_SOCKET]}"
223
239
  end
224
240
  end
225
241
 
@@ -245,25 +261,18 @@ module RSpec
245
261
  end
246
262
  end
247
263
 
248
- # Communication between abq sockets follows the following protocol:
249
- # - The first 4 bytes an unsigned 32-bit integer (big-endian) representing
250
- # the size of the rest of the message.
251
- # - The rest of the message is a JSON-encoded payload.
252
- class AbqConnBroken < StandardError
253
- end
254
-
255
264
  # Writes a message to an Abq socket using the 4-byte header protocol.
256
265
  #
257
266
  # @param socket [TCPSocket]
258
267
  # @param msg
259
268
  def self.protocol_write(msg, socket = Abq.socket)
260
269
  json_msg = JSON.dump msg
261
- begin
262
- socket.write [json_msg.bytesize].pack("N")
263
- socket.write json_msg
264
- rescue
265
- raise AbqConnBroken
266
- end
270
+ socket.write [json_msg.bytesize].pack("N")
271
+ socket.write json_msg
272
+ rescue SystemCallError, IOError
273
+ raise ConnectionBroken
274
+ rescue
275
+ raise Error
267
276
  end
268
277
 
269
278
  # Writes a message to an Abq socket using the 4-byte header protocol.
@@ -273,10 +282,16 @@ module RSpec
273
282
  def self.protocol_read(socket = Abq.socket)
274
283
  len_bytes = socket.read 4
275
284
  return :abq_done if len_bytes.nil?
285
+
276
286
  len = len_bytes.unpack1("N")
277
287
  json_msg = socket.read len
278
288
  return :abq_done if json_msg.nil?
289
+
279
290
  JSON.parse json_msg
291
+ rescue SystemCallError, IOError
292
+ raise ConnectionBroken
293
+ rescue
294
+ raise Error
280
295
  end
281
296
  end
282
297
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-abq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ayaz Hafiz
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-10 00:00:00.000000000 Z
12
+ date: 2023-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core