Skip to content

Commit 523cc77

Browse files
committed
slightly improved test
1 parent 23cec0a commit 523cc77

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

lib/concurrent/executor/timer_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def <=>(other)
101101
end
102102
end
103103

104+
private_constant :Task
105+
104106
# @!visibility private
105107
def shutdown_execution
106108
@queue.clear

spec/concurrent/executor/timer_set_spec.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ module Concurrent
2424
end
2525

2626
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
3130
end
3231

3332
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
3736
end
3837

3938
it 'immediately posts a task when the delay is zero' do
4039
Thread.should_not_receive(:new).with(any_args)
41-
expected = false
42-
subject.post(0){ expected = true }
40+
subject.post(0){ true }
4341
end
4442

4543
it 'does not execute tasks early' do
@@ -72,10 +70,9 @@ module Concurrent
7270

7371
it 'executes all tasks scheduled for the same time' do
7472
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
7976
end
8077

8178
it 'executes tasks with different times in schedule order' do

0 commit comments

Comments
 (0)