@@ -4,7 +4,7 @@ module Concurrent
4
4
5
5
describe TimerSet do
6
6
7
- let ( :executor ) { Concurrent ::SingleThreadExecutor . new }
7
+ let ( :executor ) { Concurrent ::ImmediateExecutor . new }
8
8
subject { TimerSet . new ( executor : executor ) }
9
9
10
10
after ( :each ) { subject . kill }
@@ -75,15 +75,15 @@ module Concurrent
75
75
expect ( latch . wait ( 0.2 ) ) . to be_truthy
76
76
end
77
77
78
- it 'passes all arguments to the task on execution' , buggy : true do
79
- expected = nil
78
+ it 'passes all arguments to the task on execution' do
79
+ expected = AtomicReference . new
80
80
latch = CountDownLatch . new ( 1 )
81
81
subject . post ( 0.1 , 1 , 2 , 3 ) do |*args |
82
- expected = args
82
+ expected . value = args
83
83
latch . count_down
84
84
end
85
85
expect ( latch . wait ( 0.2 ) ) . to be_truthy
86
- expect ( expected ) . to eq [ 1 , 2 , 3 ]
86
+ expect ( expected . value ) . to eq [ 1 , 2 , 3 ]
87
87
end
88
88
89
89
it 'does not execute tasks early' do
@@ -94,10 +94,10 @@ module Concurrent
94
94
expect ( Time . now . to_f - start ) . to be >= 0.19
95
95
end
96
96
97
- it 'executes all tasks scheduled for the same time' , buggy : true do
97
+ it 'executes all tasks scheduled for the same time' do
98
98
latch = CountDownLatch . new ( 5 )
99
99
5 . times { subject . post ( 0.1 ) { latch . count_down } }
100
- expect ( latch . wait ( 0.2 ) ) . to be_truthy
100
+ expect ( latch . wait ( 1 ) ) . to be_truthy
101
101
end
102
102
103
103
it 'executes tasks with different times in schedule order' do
@@ -317,38 +317,16 @@ module Concurrent
317
317
318
318
context 'termination' do
319
319
320
- it 'cancels all pending tasks on #shutdown' , buggy : true do
321
- count = 10
322
- latch = Concurrent ::CountDownLatch . new ( count )
323
- expected = AtomicFixnum . new ( 0 )
324
-
325
- count . times do |i |
326
- subject . post ( 0.2 ) { expected . increment }
327
- latch . count_down
328
- end
329
-
330
- latch . wait ( 1 )
320
+ it 'cancels all pending tasks on #shutdown' do
321
+ queue = subject . instance_variable_get ( :@queue )
322
+ expect ( queue ) . to receive ( :clear ) . with ( no_args ) . at_least ( :once )
331
323
subject . shutdown
332
- subject . wait_for_termination ( 1 )
333
-
334
- expect ( expected . value ) . to eq 0
335
324
end
336
325
337
- it 'cancels all pending tasks on #kill' , buggy : true do
338
- count = 10
339
- latch = Concurrent ::CountDownLatch . new ( count )
340
- expected = AtomicFixnum . new ( 0 )
341
-
342
- count . times do |i |
343
- subject . post ( 0.2 ) { expected . increment }
344
- latch . count_down
345
- end
346
-
347
- latch . wait ( 1 )
326
+ it 'cancels all pending tasks on #kill' do
327
+ queue = subject . instance_variable_get ( :@queue )
328
+ expect ( queue ) . to receive ( :clear ) . with ( no_args ) . at_least ( :once )
348
329
subject . kill
349
- subject . wait_for_termination ( 1 )
350
-
351
- expect ( expected . value ) . to eq 0
352
330
end
353
331
354
332
it 'stops the monitor thread on #shutdown' do
@@ -365,28 +343,20 @@ module Concurrent
365
343
expect ( timer_executor ) . not_to be_running
366
344
end
367
345
368
- it 'rejects tasks once shutdown' , buggy : true do
369
- latch = Concurrent ::CountDownLatch . new ( 1 )
370
- expected = AtomicFixnum . new ( 0 )
371
-
346
+ it 'rejects tasks once shutdown' do
347
+ queue = subject . instance_variable_get ( :@queue )
372
348
subject . shutdown
373
349
subject . wait_for_termination ( 1 )
374
-
375
- expect ( subject . post ( 0 ) { expected . increment ; latch . count_down } ) . to be_falsey
376
- latch . wait ( 0.1 )
377
- expect ( expected . value ) . to eq 0
350
+ subject . post ( 1 ) { nil }
351
+ expect ( queue ) . to be_empty
378
352
end
379
353
380
354
it 'rejects tasks once killed' do
381
- latch = Concurrent ::CountDownLatch . new ( 1 )
382
- expected = AtomicFixnum . new ( 0 )
383
-
355
+ queue = subject . instance_variable_get ( :@queue )
384
356
subject . kill
385
357
subject . wait_for_termination ( 1 )
386
-
387
- expect ( subject . post ( 0 ) { expected . increment ; latch . count_down } ) . to be_falsey
388
- latch . wait ( 0.1 )
389
- expect ( expected . value ) . to eq 0
358
+ subject . post ( 1 ) { nil }
359
+ expect ( queue ) . to be_empty
390
360
end
391
361
392
362
specify '#wait_for_termination returns true if shutdown completes before timeout' do
0 commit comments