aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_thread_queue.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-30 09:46:21 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-30 11:45:38 +0900
commitb43d6e570980a4f5d6f4c20de29024dc5df93472 (patch)
treef773f28fefa0effa0d0235182a567ff2fee7ff4c /test/ruby/test_thread_queue.rb
parent8fe359086484cd322704e57fce25ef8c41d949a8 (diff)
downloadruby-b43d6e570980a4f5d6f4c20de29024dc5df93472.tar.gz
Fixed non-working test
Diffstat (limited to 'test/ruby/test_thread_queue.rb')
-rw-r--r--test/ruby/test_thread_queue.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index ccd51b7b31..b5ee70d9dc 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -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