Skip to content

Commit 0b87569

Browse files
committed
Began refactoring tests for Condition.
1 parent 19845f6 commit 0b87569

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

spec/concurrent/atomic/condition_spec.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ module Concurrent
3232
describe '#wait without timeout' do
3333

3434
it 'should block the thread' do
35-
t = Thread.new { mutex.synchronize { subject.wait(mutex) } }
36-
sleep(0.1)
35+
latch = Concurrent::CountDownLatch.new
36+
t = Thread.new do
37+
mutex.synchronize do
38+
latch.count_down
39+
subject.wait(mutex)
40+
end
41+
end
42+
43+
latch.wait(1)
3744
expect(t.status).to eq 'sleep'
3845
t.kill
3946
end
@@ -70,8 +77,15 @@ module Concurrent
7077
describe '#wait' do
7178

7279
it 'should block the thread' do
73-
t = Thread.new { mutex.synchronize { subject.wait(mutex, 1) } }
74-
sleep(0.1)
80+
latch = Concurrent::CountDownLatch.new
81+
t = Thread.new do
82+
mutex.synchronize do
83+
latch.count_down
84+
subject.wait(mutex, 1)
85+
end
86+
end
87+
88+
latch.wait(1)
7589
expect(t.status).to eq 'sleep'
7690
t.kill
7791
end

0 commit comments

Comments
 (0)