mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fixed non-working test
This commit is contained in:
parent
8fe3590864
commit
b43d6e5709
1 changed files with 10 additions and 6 deletions
|
@ -346,21 +346,25 @@ class TestThreadQueue < Test::Unit::TestCase
|
|||
|
||||
# make sure that shutdown state is handled properly by empty? for the non-blocking case
|
||||
def test_empty_non_blocking
|
||||
return
|
||||
q = SizedQueue.new 3
|
||||
3.times{|i| q << i}
|
||||
|
||||
# these all block cos the queue is full
|
||||
prod_threads = 4.times.map{|i| Thread.new{q << 3+i}}
|
||||
sleep 0.01 until prod_threads.all?{|thr| thr.status == 'sleep'}
|
||||
q.close
|
||||
prod_threads = 4.times.map {|i|
|
||||
Thread.new {
|
||||
Thread.current.report_on_exception = false
|
||||
q << 3+i
|
||||
}
|
||||
}
|
||||
sleep 0.01 until prod_threads.all?{|thr| thr.stop?}
|
||||
|
||||
items = []
|
||||
# sometimes empty? is false but pop will raise ThreadError('empty'),
|
||||
# meaning a value is not immediately available but will be soon.
|
||||
until q.empty?
|
||||
items << q.pop(non_block=true) rescue nil
|
||||
until q.empty? and !prod_threads.any?(&:alive?)
|
||||
items << q.pop(true) rescue nil
|
||||
end
|
||||
assert_join_threads(prod_threads)
|
||||
items.compact!
|
||||
|
||||
assert_equal 7.times.to_a, items.sort
|
||||
|
|
Loading…
Add table
Reference in a new issue