Skip to content

Commit 8f59041

Browse files
committed
Improve robustness of test, fixes #218.
1 parent 9e49bee commit 8f59041

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

spec/async/semaphore_spec.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
3.times.map do |i|
6363
semaphore.async do |task|
6464
order << i
65-
task.sleep(0.1)
65+
task.yield
6666
order << i
6767
end
6868
end.collect(&:result)
@@ -72,17 +72,22 @@
7272

7373
it 'allows tasks to execute concurrently' do
7474
semaphore = Async::Semaphore.new(3)
75-
order = []
75+
concurrency = 0
76+
latch = Async::Condition.new
7677

7778
3.times.map do |i|
7879
semaphore.async do |task|
79-
order << i
80-
task.sleep(0.1)
81-
order << i
80+
concurrency += 1
81+
82+
if concurrency == 3
83+
latch.signal
84+
else
85+
latch.wait
86+
end
8287
end
83-
end.collect(&:result)
88+
end.each(&:wait)
8489

85-
expect(order).to be == [0, 1, 2, 0, 1, 2]
90+
expect(concurrency).to be == 3
8691
end
8792
end
8893

0 commit comments

Comments
 (0)