diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-21 00:32:09 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-21 00:32:09 +0000 |
commit | e2609033ab07fb38fcaf1bf37382fb6dcc2d9985 (patch) | |
tree | 5489c582bd2d0c4dd62ef588f4218b851617f535 /test/thread | |
parent | a77fb26da8a98b21a7d160f66d74435934910f74 (diff) | |
download | ruby-e2609033ab07fb38fcaf1bf37382fb6dcc2d9985.tar.gz |
* thread_sync.c: reduce the specification of Queue#close.
* Queue#close accepts no arguments.
* deq'ing on closed queue returns nil, always.
[Feature #10600]
* test/thread/test_queue.rb: catch up this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/thread')
-rw-r--r-- | test/thread/test_queue.rb | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index 13cefde641..59d51e730c 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -289,6 +289,7 @@ class TestQueue < Test::Unit::TestCase assert_raise_with_message(ClosedQueueError, /closed/){q << :nothing} assert_equal q.pop, :something assert_nil q.pop + assert_nil q.pop # non-blocking assert_raise_with_message(ThreadError, /queue empty/){q.pop(non_block=true)} end @@ -484,36 +485,11 @@ class TestQueue < Test::Unit::TestCase assert_nil t.value end - def test_close_token_exception - [->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate| - q = qcreate[] - q.close true - assert_raise(ClosedQueueError){q.pop} - end - end - - def test_close_token_loop - [->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate| - q = qcreate[] - popped_items = [] - consumer_thread = Thread.new{loop{popped_items << q.pop}; :done} - 7.times{|i| q << i} - q.close true - sleep 0.1 unless q.empty? - assert_equal :done, consumer_thread.value - assert_equal 7.times.to_a, popped_items - end - end - def test_close_twice [->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate| q = qcreate[] q.close assert_nothing_raised(ClosedQueueError){q.close} - - q = qcreate[] - q.close(true) - assert_nothing_raised(ClosedQueueError){q.close(false)} end end @@ -533,8 +509,8 @@ class TestQueue < Test::Unit::TestCase consumers = rand(7..12).times.map do Thread.new do count = 0 - loop do - i, st = q.pop + while e = q.pop + i, st = e count += 1 if i.is_a?(Fixnum) && st.is_a?(String) end count @@ -554,7 +530,7 @@ class TestQueue < Test::Unit::TestCase end producers.each &:join - q.close true + q.close # results not randomly distributed. Not sure why. # consumers.map{|thr| thr.value}.each do |x| |