@@ -24,22 +24,20 @@ module Concurrent
24
24
end
25
25
26
26
it 'executes a given task when given a Time' do
27
- expected = false
28
- subject . post ( Time . now + 0.1 ) { expected = true }
29
- sleep ( 0.2 )
30
- expected . should be_true
27
+ latch = CountDownLatch . new ( 1 )
28
+ subject . post ( Time . now + 0.1 ) { latch . count_down }
29
+ latch . wait ( 0.2 ) . should be_true
31
30
end
32
31
33
32
it 'executes a given task when given an interval in seconds' do
34
- expected = false
35
- subject . post ( 0.1 ) { expected = true }
36
- sleep ( 0.2 )
33
+ latch = CountDownLatch . new ( 1 )
34
+ subject . post ( 0.1 ) { latch . count_down }
35
+ latch . wait ( 0.2 ) . should be_true
37
36
end
38
37
39
38
it 'immediately posts a task when the delay is zero' do
40
39
Thread . should_not_receive ( :new ) . with ( any_args )
41
- expected = false
42
- subject . post ( 0 ) { expected = true }
40
+ subject . post ( 0 ) { true }
43
41
end
44
42
45
43
it 'does not execute tasks early' do
@@ -72,10 +70,9 @@ module Concurrent
72
70
73
71
it 'executes all tasks scheduled for the same time' do
74
72
pending ( 'intermittently failing on Travis CI' )
75
- expected = AtomicFixnum . new ( 0 )
76
- 5 . times { subject . post ( 0.1 ) { expected . increment } }
77
- sleep ( 0.2 )
78
- expected . value . should eq 5
73
+ latch = CountDownLatch . new ( 5 )
74
+ 5 . times { subject . post ( 0.1 ) { latch . count_down } }
75
+ latch . wait ( 0.2 ) . should eq 5
79
76
end
80
77
81
78
it 'executes tasks with different times in schedule order' do
0 commit comments