1
0
Fork 0
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:
Nobuyoshi Nakada 2019-06-30 09:46:21 +09:00
parent 8fe3590864
commit b43d6e5709
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -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