@@ -4,7 +4,7 @@ module Concurrent
44
55 describe TimerSet do
66
7- let ( :executor ) { Concurrent ::SingleThreadExecutor . new }
7+ let ( :executor ) { Concurrent ::ImmediateExecutor . new }
88 subject { TimerSet . new ( executor : executor ) }
99
1010 after ( :each ) { subject . kill }
@@ -75,15 +75,15 @@ module Concurrent
7575 expect ( latch . wait ( 0.2 ) ) . to be_truthy
7676 end
7777
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
8080 latch = CountDownLatch . new ( 1 )
8181 subject . post ( 0.1 , 1 , 2 , 3 ) do |*args |
82- expected = args
82+ expected . value = args
8383 latch . count_down
8484 end
8585 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 ]
8787 end
8888
8989 it 'does not execute tasks early' do
@@ -94,10 +94,10 @@ module Concurrent
9494 expect ( Time . now . to_f - start ) . to be >= 0.19
9595 end
9696
97- it 'executes all tasks scheduled for the same time' , buggy : true do
97+ it 'executes all tasks scheduled for the same time' do
9898 latch = CountDownLatch . new ( 5 )
9999 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
101101 end
102102
103103 it 'executes tasks with different times in schedule order' do
@@ -317,38 +317,16 @@ module Concurrent
317317
318318 context 'termination' do
319319
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 )
331323 subject . shutdown
332- subject . wait_for_termination ( 1 )
333-
334- expect ( expected . value ) . to eq 0
335324 end
336325
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 )
348329 subject . kill
349- subject . wait_for_termination ( 1 )
350-
351- expect ( expected . value ) . to eq 0
352330 end
353331
354332 it 'stops the monitor thread on #shutdown' do
@@ -365,28 +343,20 @@ module Concurrent
365343 expect ( timer_executor ) . not_to be_running
366344 end
367345
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 )
372348 subject . shutdown
373349 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
378352 end
379353
380354 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 )
384356 subject . kill
385357 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
390360 end
391361
392362 specify '#wait_for_termination returns true if shutdown completes before timeout' do
0 commit comments