in_threads 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjRiZjE4NWM3ZGY5ZjUwNGQ2ZTY0NmU1MzE0ZWQ5N2ZiZWZkMjc0OQ==
4
+ YzcyOTliODQ1ZDMyYmY1NDRiMTEyZTc4ODI0ZGViNTQ3MDJmODNhMQ==
5
5
  data.tar.gz: !binary |-
6
- YjY3NmE2NWI0NjgzNDAyN2FhNWUxYjY3OWMxNTk3ZmY2NzQzZDBiMA==
6
+ ZWNlZTE1ZjE5NmNlYzdiOWM4Y2YxNjJiMDVlYjVmMjQ2ZGY1OTM0MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjNkMzhlM2JhOGI0YzA2OTU5MWNlYzNlMDBiNjEyYTY5ZWY2ODdiYTE1MjY5
10
- NDc4MmNkNmQ2MmJkZjhhN2ZhZDdjMDg4NTdkOGU5OTYyMGQ2ZjFkYWYyZGY0
11
- MmQ3YjdiNDM4YTUyNWE2NjQ1MzIwMTA0MmQwYjY3YjRhOWRkMWM=
9
+ MDJkYjFlZDRiMTJiZjc2OTU0NWM2NGJjMWU2MjQ3YzdkZDQ3OTkxZTY0N2Uw
10
+ OWRjMTc4ODFjZTM5MTM1OGUxNDlkMTMxZGI2OTljZTRmZjAwYTZjY2I3OTMw
11
+ ZDU0YTFhODA2YzFiOWNiZDlmNzBkYmQwZWU3MWJlOWRjYmI4MmU=
12
12
  data.tar.gz: !binary |-
13
- NDBkOGUxZGFmZmY2YjE4YjFhNTk2NDJjMzQ0OTZkMWY1ZDVhMmIzZjYxYWIw
14
- NGQ1NDQ4YTg0YWExZWZiY2I3N2I0NWQyZGY5MjM3NzJkZWU3MTE0N2Y5M2Ux
15
- ZmUwZDhlMmMwMGY4NWVhY2MzYTk1MTE3ZDNmYzVjMDRjMDBhOGI=
13
+ MDgzOWFkYmIwZjEzZDVlYjcyYTZlMjU4YzQwZTYyYThmNWM0MzExMjk4ZTY5
14
+ NWIwOTlhMTA3Y2UyMjA0NzYxYTA5NTcyZWVlNmU1M2Q2M2E1ODRmNWU2OGU2
15
+ ZjBlMzI0MTI2MWMzNTA3OWM2MDdkM2MxZWZlOGE3ZDc2NGQyNTU=
data/in_threads.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'in_threads'
5
- s.version = '1.2.1'
5
+ s.version = '1.2.2'
6
6
  s.summary = %q{Execute ruby code in parallel}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = %w[lib]
17
17
 
18
- s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'rspec', '~> 3.0'
19
19
  end
@@ -27,7 +27,7 @@ class InThreads
27
27
  # Add thread to <tt>ThreadsWait</tt>, wait for finishing of one thread if limit reached
28
28
  def <<(thread)
29
29
  if @waiter.threads.length + 1 >= @count
30
- @waiter.join(thread)
30
+ @waiter.join(thread).join
31
31
  else
32
32
  @waiter.join_nowait(thread)
33
33
  end
@@ -35,7 +35,7 @@ class InThreads
35
35
 
36
36
  # Wait for waiting threads
37
37
  def finalize
38
- @waiter.all_waits
38
+ @waiter.all_waits(&:join)
39
39
  end
40
40
  end
41
41
  end
@@ -1,4 +1,6 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'rspec'
3
+ require 'in_threads'
2
4
 
3
5
  class Item
4
6
  def initialize(i)
@@ -66,7 +68,7 @@ def describe_enum_method(method, &block)
66
68
  else
67
69
  it "should not be defined" do
68
70
  exception_regexp = /^undefined method `#{Regexp.escape(method)}' .*\bInThreads\b/
69
- proc{ enum.in_threads.send(method) }.should raise_error(NoMethodError, exception_regexp)
71
+ expect{ enum.in_threads.send(method) }.to raise_error(NoMethodError, exception_regexp)
70
72
  end
71
73
  end
72
74
  end
@@ -84,38 +86,38 @@ describe "in_threads" do
84
86
  describe "consistency" do
85
87
  describe "verifying params" do
86
88
  it "should complain about using with non enumerable" do
87
- proc{ InThreads.new(1) }.should raise_error(ArgumentError)
89
+ expect{ InThreads.new(1) }.to raise_error(ArgumentError)
88
90
  end
89
91
 
90
92
  [1..10, 10.times, {}, []].each do |o|
91
93
  it "should complain about using with #{o.class}" do
92
- proc{ InThreads.new(o) }.should_not raise_error
94
+ expect{ InThreads.new(o) }.not_to raise_error
93
95
  end
94
96
  end
95
97
 
96
98
  it "should complain about using less than 2 threads" do
97
- proc{ 10.times.in_threads(1) }.should raise_error(ArgumentError)
99
+ expect{ 10.times.in_threads(1) }.to raise_error(ArgumentError)
98
100
  end
99
101
 
100
102
  it "should not complain about using 2 or more threads" do
101
- proc{ 10.times.in_threads(2) }.should_not raise_error
103
+ expect{ 10.times.in_threads(2) }.not_to raise_error
102
104
  end
103
105
  end
104
106
 
105
- describe "in_threads" do
107
+ describe "in_threads method" do
106
108
  it "should not change existing instance" do
107
109
  threaded = enum.in_threads(10)
108
- proc{ threaded.in_threads(20) }.should_not change(threaded, :thread_count)
110
+ expect{ threaded.in_threads(20) }.not_to change(threaded, :thread_count)
109
111
  end
110
112
 
111
113
  it "should create new instance with different title when called on WithProgress" do
112
114
  threaded = enum.in_threads(10)
113
115
  tthreaded = threaded.in_threads(20)
114
- threaded.thread_count.should == 10
115
- tthreaded.thread_count.should == 20
116
- tthreaded.class.should == threaded.class
117
- tthreaded.object_id.should_not == threaded.object_id
118
- tthreaded.enumerable.should == threaded.enumerable
116
+ expect(threaded.thread_count).to eq(10)
117
+ expect(tthreaded.thread_count).to eq(20)
118
+ expect(tthreaded.class).to eq(threaded.class)
119
+ expect(tthreaded.object_id).not_to eq(threaded.object_id)
120
+ expect(tthreaded.enumerable).to eq(threaded.enumerable)
119
121
  end
120
122
  end
121
123
 
@@ -138,8 +140,8 @@ describe "in_threads" do
138
140
  end
139
141
  res
140
142
  end
141
- @thread_count.should == 0
142
- @max_thread_count.should == 4
143
+ expect(@thread_count).to eq(0)
144
+ expect(@max_thread_count).to eq(4)
143
145
  end
144
146
  end
145
147
  end
@@ -159,7 +161,7 @@ describe "in_threads" do
159
161
 
160
162
  %w[each map all?].each do |method|
161
163
  it "should call underlying enumerable.each only once for #{method}" do
162
- enum.should_receive(:each_started).once
164
+ expect(enum).to receive(:each_started).once
163
165
  enum.in_threads(13).send(method, &:check?)
164
166
  end
165
167
  end
@@ -171,26 +173,39 @@ describe "in_threads" do
171
173
  pending method
172
174
  end
173
175
 
176
+ class TestException < StandardError; end
177
+
178
+ def check_test_exception(enum, &block)
179
+ expect{ block[enum.in_threads] }.to raise_exception(TestException)
180
+ expect{ block[enum.in_threads(1000)] }.to raise_exception(TestException)
181
+ end
182
+
174
183
  describe "each" do
175
184
  it "should return same enum after running" do
176
- enum.in_threads.each(&:value).should == enum
185
+ expect(enum.in_threads.each(&:value)).to eq(enum)
177
186
  end
178
187
 
179
188
  it "should execute block for each element" do
180
- enum.each{ |o| o.should_receive(:touch).once }
189
+ enum.each{ |o| expect(o).to receive(:touch).once }
181
190
  enum.in_threads.each(&:touch_n_value)
182
191
  end
183
192
 
184
193
  it "should run faster with threads" do
185
- measure{ enum.in_threads.each(&:value) }.should < measure{ enum.each(&:value) } * speed_coef
194
+ expect(measure{ enum.in_threads.each(&:value) }).to be < measure{ enum.each(&:value) } * speed_coef
186
195
  end
187
196
 
188
197
  it "should run faster with more threads" do
189
- measure{ enum.in_threads(10).each(&:value) }.should < measure{ enum.in_threads(2).each(&:value) } * speed_coef
198
+ expect(measure{ enum.in_threads(10).each(&:value) }).to be < measure{ enum.in_threads(2).each(&:value) } * speed_coef
190
199
  end
191
200
 
192
201
  it "should return same enum without block" do
193
- enum.in_threads.each.to_a.should == enum.each.to_a
202
+ expect(enum.in_threads.each.to_a).to eq(enum.each.to_a)
203
+ end
204
+
205
+ it "should raise exception in outer thread" do
206
+ check_test_exception(enum) do |threaded|
207
+ threaded.each{ raise TestException }
208
+ end
194
209
  end
195
210
  end
196
211
 
@@ -199,35 +214,41 @@ describe "in_threads" do
199
214
  let(:runner){ proc{ |o, i| o.value } }
200
215
 
201
216
  it "should return same result with threads" do
202
- enum.in_threads.send(method, &runner).should == enum.send(method, &runner)
217
+ expect(enum.in_threads.send(method, &runner)).to eq(enum.send(method, &runner))
203
218
  end
204
219
 
205
220
  it "should fire same objects" do
206
- enum.send(method){ |o, i| o.should_receive(:touch).with(i).once }
221
+ enum.send(method){ |o, i| expect(o).to receive(:touch).with(i).once }
207
222
  enum.in_threads.send(method){ |o, i| o.touch_n_value(i) }
208
223
  end
209
224
 
210
225
  it "should run faster with threads" do
211
- measure{ enum.in_threads.send(method, &runner) }.should < measure{ enum.send(method, &runner) } * speed_coef
226
+ expect(measure{ enum.in_threads.send(method, &runner) }).to be < measure{ enum.send(method, &runner) } * speed_coef
212
227
  end
213
228
 
214
229
  it "should return same enum without block" do
215
- enum.in_threads.send(method).to_a.should == enum.send(method).to_a
230
+ expect(enum.in_threads.send(method).to_a).to eq(enum.send(method).to_a)
231
+ end
232
+
233
+ it "should raise exception in outer thread" do
234
+ check_test_exception(enum) do |threaded|
235
+ threaded.send(method){ raise TestException }
236
+ end
216
237
  end
217
238
  end
218
239
  end
219
240
 
220
241
  describe "reverse_each" do
221
242
  it "should return same result with threads" do
222
- enum.in_threads.reverse_each(&:value).should == enum.reverse_each(&:value)
243
+ expect(enum.in_threads.reverse_each(&:value)).to eq(enum.reverse_each(&:value))
223
244
  end
224
245
 
225
246
  it "should fire same objects in reverse order" do
226
247
  @order = double('order', :notify => nil)
227
- @order.should_receive(:notify).with(enum.last).ordered
228
- @order.should_receive(:notify).with(enum[enum.length / 2]).ordered
229
- @order.should_receive(:notify).with(enum.first).ordered
230
- enum.reverse_each{ |o| o.should_receive(:touch).once }
248
+ expect(@order).to receive(:notify).with(enum.last).ordered
249
+ expect(@order).to receive(:notify).with(enum[enum.length / 2]).ordered
250
+ expect(@order).to receive(:notify).with(enum.first).ordered
251
+ enum.reverse_each{ |o| expect(o).to receive(:touch).once }
231
252
  @mutex = Mutex.new
232
253
  enum.in_threads.reverse_each do |o|
233
254
  @mutex.synchronize{ @order.notify(o) }
@@ -236,11 +257,17 @@ describe "in_threads" do
236
257
  end
237
258
 
238
259
  it "should run faster with threads" do
239
- measure{ enum.in_threads.reverse_each(&:value) }.should < measure{ enum.reverse_each(&:value) } * speed_coef
260
+ expect(measure{ enum.in_threads.reverse_each(&:value) }).to be < measure{ enum.reverse_each(&:value) } * speed_coef
240
261
  end
241
262
 
242
263
  it "should return same enum without block" do
243
- enum.in_threads.reverse_each.to_a.should == enum.reverse_each.to_a
264
+ expect(enum.in_threads.reverse_each.to_a).to eq(enum.reverse_each.to_a)
265
+ end
266
+
267
+ it "should raise exception in outer thread" do
268
+ check_test_exception(enum) do |threaded|
269
+ threaded.reverse_each{ raise TestException }
270
+ end
244
271
  end
245
272
  end
246
273
 
@@ -252,7 +279,7 @@ describe "in_threads" do
252
279
  let(:enum){ 100.times.map{ |i| ValueItem.new(i, i % 2 == 1) } }
253
280
 
254
281
  it "should return same result with threads" do
255
- enum.in_threads.send(method, &:check?).should == enum.send(method, &:check?)
282
+ expect(enum.in_threads.send(method, &:check?)).to eq(enum.send(method, &:check?))
256
283
  end
257
284
 
258
285
  it "should fire same objects but not all" do
@@ -266,14 +293,20 @@ describe "in_threads" do
266
293
  @mutex = Mutex.new
267
294
  enum.in_threads.send(method){ |o| @mutex.synchronize{ @a << o }; o.check? }
268
295
 
269
- @a.length.should >= a.length
270
- @a.length.should <= enum.length * 0.5
296
+ expect(@a.length).to be >= a.length
297
+ expect(@a.length).to be <= enum.length * 0.5
271
298
  end
272
299
 
273
300
  it "should run faster with threads" do
274
301
  boolean = %w[all? drop_while take_while].include?(method)
275
302
  enum = 30.times.map{ |i| ValueItem.new(i, boolean) }
276
- measure{ enum.in_threads.send(method, &:check?) }.should < measure{ enum.send(method, &:check?) } * speed_coef
303
+ expect(measure{ enum.in_threads.send(method, &:check?) }).to be < measure{ enum.send(method, &:check?) } * speed_coef
304
+ end
305
+
306
+ it "should raise exception in outer thread" do
307
+ check_test_exception(enum) do |threaded|
308
+ threaded.send(method){ raise TestException }
309
+ end
277
310
  end
278
311
  end
279
312
  end
@@ -281,16 +314,22 @@ describe "in_threads" do
281
314
  %w[partition find_all select reject count].each do |method|
282
315
  describe method do
283
316
  it "should return same result with threads" do
284
- enum.in_threads.send(method, &:check?).should == enum.send(method, &:check?)
317
+ expect(enum.in_threads.send(method, &:check?)).to eq(enum.send(method, &:check?))
285
318
  end
286
319
 
287
320
  it "should fire same objects" do
288
- enum.send(method){ |o| o.should_receive(:touch).once }
321
+ enum.send(method){ |o| expect(o).to receive(:touch).once }
289
322
  enum.in_threads.send(method, &:touch_n_check?)
290
323
  end
291
324
 
292
325
  it "should run faster with threads" do
293
- measure{ enum.in_threads.send(method, &:check?) }.should < measure{ enum.send(method, &:check?) } * speed_coef
326
+ expect(measure{ enum.in_threads.send(method, &:check?) }).to be < measure{ enum.send(method, &:check?) } * speed_coef
327
+ end
328
+
329
+ it "should raise exception in outer thread" do
330
+ check_test_exception(enum) do |threaded|
331
+ threaded.send(method){ raise TestException }
332
+ end
294
333
  end
295
334
  end
296
335
  end
@@ -298,16 +337,22 @@ describe "in_threads" do
298
337
  %w[collect map group_by max_by min_by minmax_by sort_by].each do |method|
299
338
  describe method do
300
339
  it "should return same result with threads" do
301
- enum.in_threads.send(method, &:value).should == enum.send(method, &:value)
340
+ expect(enum.in_threads.send(method, &:value)).to eq(enum.send(method, &:value))
302
341
  end
303
342
 
304
343
  it "should fire same objects" do
305
- enum.send(method){ |o| o.should_receive(:touch).once; 0 }
344
+ enum.send(method){ |o| expect(o).to receive(:touch).once; 0 }
306
345
  enum.in_threads.send(method, &:touch_n_value)
307
346
  end
308
347
 
309
348
  it "should run faster with threads" do
310
- measure{ enum.in_threads.send(method, &:value) }.should < measure{ enum.send(method, &:value) } * speed_coef
349
+ expect(measure{ enum.in_threads.send(method, &:value) }).to be < measure{ enum.send(method, &:value) } * speed_coef
350
+ end
351
+
352
+ it "should raise exception in outer thread" do
353
+ check_test_exception(enum) do |threaded|
354
+ threaded.send(method){ raise TestException }
355
+ end
311
356
  end
312
357
  end
313
358
  end
@@ -317,20 +362,26 @@ describe "in_threads" do
317
362
  let(:runner){ proc{ |a| a.each(&:value) } }
318
363
 
319
364
  it "should fire same objects" do
320
- enum.send(method, 3){ |a| a.first.should_receive(:touch).with(a).once }
365
+ enum.send(method, 3){ |a| expect(a.first).to receive(:touch).with(a).once }
321
366
  enum.in_threads.send(method, 3){ |a| a.first.touch_n_value(a) }
322
367
  end
323
368
 
324
369
  it "should return same with block" do
325
- enum.in_threads.send(method, 3, &runner).should == enum.send(method, 3, &runner)
370
+ expect(enum.in_threads.send(method, 3, &runner)).to eq(enum.send(method, 3, &runner))
326
371
  end
327
372
 
328
373
  it "should run faster with threads" do
329
- measure{ enum.in_threads.send(method, 3, &runner) }.should < measure{ enum.send(method, 3, &runner) } * speed_coef
374
+ expect(measure{ enum.in_threads.send(method, 3, &runner) }).to be < measure{ enum.send(method, 3, &runner) } * speed_coef
330
375
  end
331
376
 
332
377
  it "should return same without block" do
333
- enum.in_threads.send(method, 3).to_a.should == enum.send(method, 3).to_a
378
+ expect(enum.in_threads.send(method, 3).to_a).to eq(enum.send(method, 3).to_a)
379
+ end
380
+
381
+ it "should raise exception in outer thread" do
382
+ check_test_exception(enum) do |threaded|
383
+ threaded.send(method, 3){ raise TestException }
384
+ end
334
385
  end
335
386
  end
336
387
  end
@@ -339,35 +390,47 @@ describe "in_threads" do
339
390
  let(:runner){ proc{ |a| a.each(&:value) } }
340
391
 
341
392
  it "should fire same objects" do
342
- enum.zip(enum, enum){ |a| a.first.should_receive(:touch).with(a).once }
393
+ enum.zip(enum, enum){ |a| expect(a.first).to receive(:touch).with(a).once }
343
394
  enum.in_threads.zip(enum, enum){ |a| a.first.touch_n_value(a) }
344
395
  end
345
396
 
346
397
  it "should return same with block" do
347
- enum.in_threads.zip(enum, enum, &runner).should == enum.zip(enum, enum, &runner)
398
+ expect(enum.in_threads.zip(enum, enum, &runner)).to eq(enum.zip(enum, enum, &runner))
348
399
  end
349
400
 
350
401
  it "should run faster with threads" do
351
- measure{ enum.in_threads.zip(enum, enum, &runner) }.should < measure{ enum.zip(enum, enum, &runner) } * speed_coef
402
+ expect(measure{ enum.in_threads.zip(enum, enum, &runner) }).to be < measure{ enum.zip(enum, enum, &runner) } * speed_coef
352
403
  end
353
404
 
354
405
  it "should return same without block" do
355
- enum.in_threads.zip(enum, enum).should == enum.zip(enum, enum)
406
+ expect(enum.in_threads.zip(enum, enum)).to eq(enum.zip(enum, enum))
407
+ end
408
+
409
+ it "should raise exception in outer thread" do
410
+ check_test_exception(enum) do |threaded|
411
+ threaded.zip(enum, enum){ raise TestException }
412
+ end
356
413
  end
357
414
  end
358
415
 
359
416
  describe "cycle" do
360
417
  it "should fire same objects" do
361
- enum.cycle(1){ |o| o.should_receive(:touch).exactly(3).times }
418
+ enum.cycle(1){ |o| expect(o).to receive(:touch).exactly(3).times }
362
419
  enum.in_threads.cycle(3, &:touch_n_value)
363
420
  end
364
421
 
365
422
  it "should run faster with threads" do
366
- measure{ enum.in_threads.cycle(3, &:value) }.should < measure{ enum.cycle(3, &:value) } * speed_coef
423
+ expect(measure{ enum.in_threads.cycle(3, &:value) }).to be < measure{ enum.cycle(3, &:value) } * speed_coef
367
424
  end
368
425
 
369
426
  it "should return same enum without block" do
370
- enum.in_threads.cycle(3).to_a.should == enum.cycle(3).to_a
427
+ expect(enum.in_threads.cycle(3).to_a).to eq(enum.cycle(3).to_a)
428
+ end
429
+
430
+ it "should raise exception in outer thread" do
431
+ check_test_exception(enum) do |threaded|
432
+ threaded.cycle{ raise TestException }
433
+ end
371
434
  end
372
435
  end
373
436
 
@@ -375,20 +438,26 @@ describe "in_threads" do
375
438
  let(:matcher){ Item::HalfMatcher.new }
376
439
 
377
440
  it "should fire same objects" do
378
- enum.each{ |o| o.should_receive(:touch).exactly(matcher === o ? 1 : 0).times }
441
+ enum.each{ |o| expect(o).to receive(:touch).exactly(matcher === o ? 1 : 0).times }
379
442
  enum.in_threads.grep(matcher, &:touch_n_value)
380
443
  end
381
444
 
382
445
  it "should return same with block" do
383
- enum.in_threads.grep(matcher, &:value).should == enum.grep(matcher, &:value)
446
+ expect(enum.in_threads.grep(matcher, &:value)).to eq(enum.grep(matcher, &:value))
384
447
  end
385
448
 
386
449
  it "should run faster with threads" do
387
- measure{ enum.in_threads.grep(matcher, &:value) }.should < measure{ enum.grep(matcher, &:value) } * speed_coef
450
+ expect(measure{ enum.in_threads.grep(matcher, &:value) }).to be < measure{ enum.grep(matcher, &:value) } * speed_coef
388
451
  end
389
452
 
390
453
  it "should return same without block" do
391
- enum.in_threads.grep(matcher).should == enum.grep(matcher)
454
+ expect(enum.in_threads.grep(matcher)).to eq(enum.grep(matcher))
455
+ end
456
+
457
+ it "should raise exception in outer thread" do
458
+ check_test_exception(enum) do |threaded|
459
+ threaded.grep(matcher){ raise TestException }
460
+ end
392
461
  end
393
462
  end
394
463
 
@@ -406,14 +475,14 @@ describe "in_threads" do
406
475
  let(:runner){ proc{ |o| ValueItem.new(0, o).value } }
407
476
 
408
477
  it "should return same result with threads" do
409
- enum.in_threads.each_entry(&runner).should == enum.each_entry(&runner)
478
+ expect(enum.in_threads.each_entry(&runner)).to eq(enum.each_entry(&runner))
410
479
  end
411
480
 
412
481
  it "should execute block for each element" do
413
482
  @order = double('order')
414
- @order.should_receive(:notify).with(1).exactly(10).times.ordered
415
- @order.should_receive(:notify).with([2, 3]).exactly(10).times.ordered
416
- @order.should_receive(:notify).with([4, 5, 6]).exactly(10).times.ordered
483
+ expect(@order).to receive(:notify).with(1).exactly(10).times.ordered
484
+ expect(@order).to receive(:notify).with([2, 3]).exactly(10).times.ordered
485
+ expect(@order).to receive(:notify).with([4, 5, 6]).exactly(10).times.ordered
417
486
  @mutex = Mutex.new
418
487
  enum.in_threads.each_entry do |o|
419
488
  @mutex.synchronize{ @order.notify(o) }
@@ -422,11 +491,17 @@ describe "in_threads" do
422
491
  end
423
492
 
424
493
  it "should run faster with threads" do
425
- measure{ enum.in_threads.each_entry(&runner) }.should < measure{ enum.each_entry(&runner) } * speed_coef
494
+ expect(measure{ enum.in_threads.each_entry(&runner) }).to be < measure{ enum.each_entry(&runner) } * speed_coef
426
495
  end
427
496
 
428
497
  it "should return same enum without block" do
429
- enum.in_threads.each_entry.to_a.should == enum.each_entry.to_a
498
+ expect(enum.in_threads.each_entry.to_a).to eq(enum.each_entry.to_a)
499
+ end
500
+
501
+ it "should raise exception in outer thread" do
502
+ check_test_exception(enum) do |threaded|
503
+ threaded.each_entry{ raise TestException }
504
+ end
430
505
  end
431
506
  end
432
507
 
@@ -436,20 +511,26 @@ describe "in_threads" do
436
511
  let(:runner){ proc{ |a| a.map(&:value) } }
437
512
 
438
513
  it "should return same result with threads" do
439
- enum.in_threads.send(method, &runner).should == enum.send(method, &runner)
514
+ expect(enum.in_threads.send(method, &runner)).to eq(enum.send(method, &runner))
440
515
  end
441
516
 
442
517
  it "should fire same objects" do
443
- enum.send(method){ |a| a.each{ |o| o.should_receive(:touch).with(a).once } }
518
+ enum.send(method){ |a| a.each{ |o| expect(o).to receive(:touch).with(a).once } }
444
519
  enum.in_threads.send(method){ |a| a.each{ |o| o.touch_n_value(a) } }
445
520
  end
446
521
 
447
522
  it "should run faster with threads" do
448
- measure{ enum.in_threads.send(method, &runner) }.should < measure{ enum.send(method, &runner) } * speed_coef
523
+ expect(measure{ enum.in_threads.send(method, &runner) }).to be < measure{ enum.send(method, &runner) } * speed_coef
449
524
  end
450
525
 
451
526
  it "should return same enum without block" do
452
- enum.in_threads.send(method).to_a.should == enum.send(method).to_a
527
+ expect(enum.in_threads.send(method).to_a).to eq(enum.send(method).to_a)
528
+ end
529
+
530
+ it "should raise exception in outer thread" do
531
+ check_test_exception(enum) do |threaded|
532
+ threaded.send(method){ raise TestException }
533
+ end
453
534
  end
454
535
  end
455
536
  end
@@ -459,7 +540,13 @@ describe "in_threads" do
459
540
  describe method do
460
541
  it "should return same result" do
461
542
  combiner = proc{ |memo, o| memo + o.value }
462
- enum.in_threads.send(method, 0, &combiner).should == enum.send(method, 0, &combiner)
543
+ expect(enum.in_threads.send(method, 0, &combiner)).to eq(enum.send(method, 0, &combiner))
544
+ end
545
+
546
+ it "should raise exception in outer thread" do
547
+ check_test_exception(enum) do |threaded|
548
+ threaded.send(method){ raise TestException }
549
+ end
463
550
  end
464
551
  end
465
552
  end
@@ -468,7 +555,13 @@ describe "in_threads" do
468
555
  describe method do
469
556
  it "should return same result" do
470
557
  comparer = proc{ |a, b| a.value <=> b.value }
471
- enum.in_threads.send(method, &comparer).should == enum.send(method, &comparer)
558
+ expect(enum.in_threads.send(method, &comparer)).to eq(enum.send(method, &comparer))
559
+ end
560
+
561
+ it "should raise exception in outer thread" do
562
+ check_test_exception(enum) do |threaded|
563
+ threaded.send(method){ raise TestException }
564
+ end
472
565
  end
473
566
  end
474
567
  end
@@ -476,7 +569,7 @@ describe "in_threads" do
476
569
  %w[to_a entries].each do |method|
477
570
  describe method do
478
571
  it "should return same result" do
479
- enum.in_threads.send(method).should == enum.send(method)
572
+ expect(enum.in_threads.send(method)).to eq(enum.send(method))
480
573
  end
481
574
  end
482
575
  end
@@ -484,7 +577,7 @@ describe "in_threads" do
484
577
  %w[drop take].each do |method|
485
578
  describe method do
486
579
  it "should return same result" do
487
- enum.in_threads.send(method, 2).should == enum.send(method, 2)
580
+ expect(enum.in_threads.send(method, 2)).to eq(enum.send(method, 2))
488
581
  end
489
582
  end
490
583
  end
@@ -492,8 +585,8 @@ describe "in_threads" do
492
585
  %w[first].each do |method|
493
586
  describe method do
494
587
  it "should return same result" do
495
- enum.in_threads.send(method).should == enum.send(method)
496
- enum.in_threads.send(method, 3).should == enum.send(method, 3)
588
+ expect(enum.in_threads.send(method)).to eq(enum.send(method))
589
+ expect(enum.in_threads.send(method, 3)).to eq(enum.send(method, 3))
497
590
  end
498
591
  end
499
592
  end
@@ -501,7 +594,7 @@ describe "in_threads" do
501
594
  %w[include? member?].each do |method|
502
595
  describe method do
503
596
  it "should return same result" do
504
- enum.in_threads.send(method, enum[10]).should == enum.send(method, enum[10])
597
+ expect(enum.in_threads.send(method, enum[10])).to eq(enum.send(method, enum[10]))
505
598
  end
506
599
  end
507
600
  end
@@ -510,14 +603,26 @@ describe "in_threads" do
510
603
  let(:runner){ proc{ |o, h| h[o.value] = true } }
511
604
 
512
605
  it "should return same result" do
513
- enum.in_threads.each_with_object({}, &runner).should == enum.each_with_object({}, &runner)
606
+ expect(enum.in_threads.each_with_object({}, &runner)).to eq(enum.each_with_object({}, &runner))
607
+ end
608
+
609
+ it "should raise exception in outer thread" do
610
+ check_test_exception(enum) do |threaded|
611
+ threaded.each_with_object({}){ raise TestException }
612
+ end
514
613
  end
515
614
  end
516
615
 
517
616
  %w[chunk slice_before].each do |method|
518
617
  describe_enum_method method do
519
618
  it "should return same result" do
520
- enum.in_threads.send(method, &:check?).to_a.should == enum.send(method, &:check?).to_a
619
+ expect(enum.in_threads.send(method, &:check?).to_a).to eq(enum.send(method, &:check?).to_a)
620
+ end
621
+
622
+ it "should raise exception in outer thread" do
623
+ check_test_exception(enum) do |threaded|
624
+ threaded.send(method){ raise TestException }.to_a
625
+ end
521
626
  end
522
627
  end
523
628
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_threads
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-06 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.0'
27
27
  description:
28
28
  email:
29
29
  executables: []
@@ -41,7 +41,6 @@ files:
41
41
  - lib/in_threads/filler.rb
42
42
  - lib/in_threads/thread_limiter.rb
43
43
  - spec/in_threads_spec.rb
44
- - spec/spec_helper.rb
45
44
  homepage: http://github.com/toy/in_threads
46
45
  licenses:
47
46
  - MIT
@@ -68,4 +67,4 @@ specification_version: 4
68
67
  summary: Execute ruby code in parallel
69
68
  test_files:
70
69
  - spec/in_threads_spec.rb
71
- - spec/spec_helper.rb
70
+ has_rdoc:
data/spec/spec_helper.rb DELETED
@@ -1,3 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'rspec'
3
- require 'in_threads'