Skip to content

Commit 02f6906

Browse files
committed
Refactored Condition and Exchanger tests that directly check thread status.
1 parent 9a5d32a commit 02f6906

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

spec/concurrent/atomic/condition_spec.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ module Concurrent
22

33
describe Condition do
44

5+
after(:each) do
6+
subject.broadcast
7+
end
8+
59
context 'with no waiting threads' do
610
describe '#signal' do
711
it 'should return immediately' do
@@ -37,7 +41,6 @@ module Concurrent
3741

3842
latch_1.wait(1)
3943
latch_2.wait(0.1)
40-
expect(t.status).to eq 'sleep'
4144
expect(latch_2.count).to eq 1
4245
t.kill
4346
end
@@ -119,7 +122,6 @@ module Concurrent
119122

120123
latch_1.wait(1)
121124
latch_2.wait(0.1)
122-
expect(t.status).to eq 'sleep'
123125
expect(latch_2.count).to eq 1
124126
t.kill
125127
end
@@ -213,13 +215,24 @@ module Concurrent
213215

214216
it 'should block threads' do
215217
mutex = Mutex.new
216-
latch = Concurrent::CountDownLatch.new(2)
217-
t1 = Thread.new { mutex.synchronize { latch.count_down; subject.wait(mutex) } }
218-
t2 = Thread.new { mutex.synchronize { latch.count_down; subject.wait(mutex) } }
219-
latch.wait(1)
218+
latch_1 = Concurrent::CountDownLatch.new(2)
219+
latch_2 = Concurrent::CountDownLatch.new(2)
220+
221+
threads = 2.times.collect do
222+
Thread.new do
223+
mutex.synchronize do
224+
latch_1.count_down
225+
subject.wait(mutex)
226+
latch_2.count_down
227+
end
228+
end
229+
end
230+
231+
latch_1.wait(1)
220232
sleep(0.1)
221-
[t1, t2].each { |t| expect(t.status).to eq 'sleep' }
222-
[t1, t2].each { |t| t.kill }
233+
expect(latch_2.count).to eq 2
234+
235+
threads.each { |t| t.kill }
223236
end
224237
end
225238

spec/concurrent/exchanger_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module Concurrent
2020

2121
latch_1.wait(1)
2222
latch_2.wait(0.1)
23-
expect(t.status).to eq 'sleep'
2423
expect(latch_2.count).to eq 1
2524
t.kill
2625
end

yardoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit db7483b80f6efb7df9930f0031508d7e2eb6bad0
1+
Subproject commit 5aff4706f70d757c15830edd66d74759ff364eda

0 commit comments

Comments
 (0)