turbo_test 0.1.0 → 0.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: 7cfabcac4630bd19d2529fa63dc7022e4c7dddf518afe98284a838c10ec0e0cf
4
- data.tar.gz: 23941350f74476d097e5e4af2c65d877265c6a6b5b32911f68b6b8aae76230a8
3
+ metadata.gz: 7f598fcd0bc09d2a885b3d0440eabbfa54c2718fae7f39d9f8b853fa37503474
4
+ data.tar.gz: 348390cf74c0b7ba9c05d806eb2e84dd9571b3851cac2ae6dfd98898d2531a35
5
5
  SHA512:
6
- metadata.gz: 5430e363ce617c8d0581a6c2cceed6477c63eed7234636ed031a97447ff9f512d53d269be17df4ff9e9a139493cd67d41da2f731a659f59838ddba98bd8396dd
7
- data.tar.gz: 316141c95de82103149a2d57e532e08f252797e8f4953c2493020906b77cf8c252d20252dcfaccea1df1c9145407848611db0c358ab5baa430d867cf42d115d7
6
+ metadata.gz: 2afcc1b037df3aa41ba017861939fbfff7fe7ff9e861026f56aa3771504344e6b2de58b4eecccfa963e1bca9688e789d931c7a51c2949353526a99e6847017ad
7
+ data.tar.gz: 4b1270405702e4f9ccdd736c6bdbcfd75e61fa02bcc0080b1317cc1c21d42f2152cc8fc1cd8cee3e3013538f54dbf2f369f281239739788e7ee3bac88fac74ec
@@ -68,12 +68,7 @@ module TurboTest
68
68
  [RSpec::Job, path]
69
69
  end
70
70
 
71
- results = server.host(queue)
72
-
73
- server.workers
74
- server.wait
75
-
76
- return results.read
71
+ return server.run(queue)
77
72
  end
78
73
  end
79
74
  end
@@ -24,6 +24,9 @@ require 'async'
24
24
  require 'async/container'
25
25
  require 'async/io/unix_endpoint'
26
26
  require 'async/io/shared_endpoint'
27
+
28
+ require 'async/io/threads'
29
+
27
30
  require 'msgpack'
28
31
 
29
32
  module TurboTest
@@ -49,14 +52,10 @@ module TurboTest
49
52
  class Server
50
53
  def initialize(configuration, endpoint = nil)
51
54
  @configuration = configuration
52
- @endpoint = endpoint || Async::IO::Endpoint.unix('turbo_test.ipc')
55
+ @endpoint = endpoint || Async::IO::Endpoint.unix("turbo_test-#{Process.pid}.ipc")
53
56
  @wrapper = Wrapper.new
54
57
 
55
58
  @container = Async::Container.new
56
-
57
- @bound_endpoint = Sync do
58
- Async::IO::SharedEndpoint.bound(@endpoint)
59
- end
60
59
  end
61
60
 
62
61
  def host(queue)
@@ -73,9 +72,13 @@ module TurboTest
73
72
  }
74
73
 
75
74
  Async do |task|
75
+ bound_endpoint = Sync do
76
+ Async::IO::SharedEndpoint.bound(@endpoint)
77
+ end
78
+
76
79
  instance.ready!
77
80
 
78
- @bound_endpoint.accept do |peer|
81
+ bound_endpoint.accept do |peer|
79
82
  # Console.logger.info(self) {"Incoming connection from #{peer}..."}
80
83
 
81
84
  packer = @wrapper.packer(peer)
@@ -123,8 +126,9 @@ module TurboTest
123
126
  end
124
127
  end
125
128
  end
129
+
130
+ bound_endpoint.close
126
131
  end
127
-
128
132
  ensure
129
133
  Console.logger.info("Writing results")
130
134
  @wrapper.packer(output).write(statistics).flush
@@ -159,8 +163,9 @@ module TurboTest
159
163
  def workers
160
164
  @container.run(name: "#{self.class} Worker") do |instance|
161
165
  Async do |task|
166
+ sleep(rand)
162
167
  @endpoint.connect do |peer|
163
- instance.ready!
168
+ threads = Async::IO::Threads.new
164
169
 
165
170
  packer = @wrapper.packer(peer)
166
171
  unpacker = @wrapper.unpacker(peer)
@@ -168,6 +173,8 @@ module TurboTest
168
173
  packer.write([:ready])
169
174
  packer.flush
170
175
 
176
+ instance.ready!
177
+
171
178
  unpacker.each do |message|
172
179
  command, tail = message
173
180
 
@@ -178,10 +185,14 @@ module TurboTest
178
185
  klass, *arguments = *tail
179
186
 
180
187
  begin
181
- result = klass.new(*arguments).call(packer: packer)
188
+ # We run this in a separate thread to keep it isolated from the worker loop:
189
+ result = threads.async do
190
+ klass.new(*arguments).call(packer: packer)
191
+ end.wait
192
+
182
193
  packer.write([:result, result])
183
194
  rescue Exception => exception
184
- packer.write([:error, exception, exception.backtrace])
195
+ packer.write([:error, exception.class, exception.backtrace])
185
196
  end
186
197
 
187
198
  packer.write([:ready])
@@ -191,13 +202,27 @@ module TurboTest
191
202
  end
192
203
  end
193
204
  end
205
+ rescue Errno::ECONNREFUSED
206
+ # Host is finished already.
194
207
  end
195
208
  end
196
209
  end
197
210
 
198
- def wait
211
+ def run(queue)
212
+ # Start the host:
213
+ results = self.host(queue)
214
+
215
+ # Wait until the host is ready:
216
+ @container.wait_until_ready
217
+
218
+ # Start the workers:
219
+ self.workers
220
+
221
+ # Wait for the container to finish:
199
222
  @container.wait
200
- @bound_endpoint.close
223
+
224
+ # Read the results from the host:
225
+ return results.read
201
226
  end
202
227
  end
203
228
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module TurboTest
24
- VERSION = "0.1.0"
24
+ VERSION = "0.1.1"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-01 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-container
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.0.3
120
+ rubygems_version: 3.2.3
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Press the turbo button... for your tests.