Skip to content

Commit 54441b1

Browse files
committed
Fix brittle test
1 parent 7bc9f58 commit 54441b1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

spec/concurrent/executor/timer_set_spec.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ module Concurrent
9292
end
9393

9494
it 'executes tasks with different times in scheduled time' do
95-
expected = []
96-
subject.post(0.2){ expected << 2 }
97-
subject.post(0.1){ expected << 1 }
98-
sleep(0.15)
99-
expect(expected).to eq [1]
100-
sleep(0.1)
101-
expect(expected).to eq [1,2]
95+
expected = Queue.new
96+
subject.post(0.2) { expected << [2, Time.now] }
97+
subject.post(0.1) { expected << [1, Time.now] }
98+
99+
number, time1 = expected.pop
100+
expect(number).to eq 1
101+
102+
number, time2 = expected.pop
103+
expect(number).to eq 2
104+
expect(time2 - time1).to be > 0.01
102105
end
103106

104107
it 'cancels all pending tasks on #shutdown' do

0 commit comments

Comments
 (0)