Skip to content

Commit 16b584f

Browse files
committed
Still more refactored tests.
1 parent 7b520d9 commit 16b584f

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

spec/concurrent/atomic/count_down_latch_spec.rb

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,44 @@ def subject.simulate_spurious_wake_up
106106
end
107107

108108
it 'should resist to spurious wake ups without timeout' do
109-
@expected = false
110-
Thread.new { subject.wait; @expected = true }
109+
latch = Concurrent::CountDownLatch.new(1)
110+
expected = false
111111

112-
sleep(0.1)
112+
t = Thread.new do
113+
latch.wait(1)
114+
subject.wait
115+
expected = true
116+
end
117+
118+
latch.count_down
119+
t.join(0.1)
113120
subject.simulate_spurious_wake_up
114121

115-
sleep(0.1)
116-
expect(@expected).to be_falsey
122+
t.join(0.1)
123+
expect(expected).to be_falsey
117124
end
118125

119126
it 'should resist to spurious wake ups with timeout' do
120-
@expected = false
121-
Thread.new { subject.wait(0.5); @expected = true }
127+
start_latch = Concurrent::CountDownLatch.new(1)
128+
finish_latch = Concurrent::CountDownLatch.new(1)
129+
expected = false
130+
131+
t = Thread.new do
132+
start_latch.wait(1)
133+
subject.wait(0.5)
134+
expected = true
135+
finish_latch.count_down
136+
end
122137

123-
sleep(0.1)
138+
start_latch.count_down
139+
t.join(0.1)
124140
subject.simulate_spurious_wake_up
125141

126-
sleep(0.1)
127-
expect(@expected).to be_falsey
142+
t.join(0.1)
143+
expect(expected).to be_falsey
128144

129-
sleep(0.4)
130-
expect(@expected).to be_truthy
145+
finish_latch.wait(1)
146+
expect(expected).to be_truthy
131147
end
132148
end
133149
end

spec/concurrent/executor/timer_set_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module Concurrent
106106
start = Time.now.to_f
107107
subject.post(0.2){ latch.count_down }
108108
expect(latch.wait(1)).to be true
109-
expect(Time.now.to_f - start).to be_within(0.1).of(0.2)
109+
expect(Time.now.to_f - start).to be >= 0.2
110110
end
111111

112112
it 'executes all tasks scheduled for the same time' do

0 commit comments

Comments
 (0)