Skip to content

Commit 9ce2910

Browse files
committed
Optimise TestAtomicThreadPool#test_queue_length
1 parent ff890c6 commit 9ce2910

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

test/atomic-ruby/test_atomic_thread_pool.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ def test_length
8989
end
9090

9191
def test_queue_length
92+
should_sleep = AtomicBoolean.new(true)
9293
pool = AtomicThreadPool.new(size: 2)
93-
5.times { pool << proc { sleep 1 } }
94-
assert_operator pool.queue_length, :>=, 3
94+
5.times { pool << proc { sleep 0.1 while should_sleep.true? } }
95+
sleep 0.1
96+
assert_equal 3, pool.queue_length
9597
assert_equal pool.queue_size, pool.queue_length
98+
should_sleep.make_false
9699
pool.shutdown
97100
assert_equal 0, pool.queue_length
98101
assert_equal pool.queue_size, pool.queue_length

0 commit comments

Comments
 (0)