Skip to content

Commit 047bc12

Browse files
committed
Addressed an intermittently failing Exhcnager spec.
1 parent 21a23cd commit 047bc12

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

spec/concurrent/exchanger_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ module Concurrent
4949

5050
context 'with timeout' do
5151
it 'should block until timeout' do
52-
value = 0
5352

54-
t = Thread.new { value = exchanger.exchange(2, 0.2) }
53+
latch = Concurrent::CountDownLatch.new(1)
54+
value = 0
55+
start = Time.now.to_f
5556

56-
sleep(0.1)
57-
t.status.should eq 'sleep'
57+
t = Thread.new do
58+
value = exchanger.exchange(2, 0.2)
59+
latch.count_down
60+
end
5861

59-
sleep(0.2)
62+
latch.wait(1)
6063

64+
(Time.now.to_f - start).should >= 0.2
65+
t.status.should be_false
6166
value.should be_nil
6267
end
6368
end

0 commit comments

Comments
 (0)