summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 03:48:42 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-14 03:48:42 +0000
commitd88502b70fecc39964157829f526b67ebe2210c7 (patch)
tree5380d81cb748109c0e3d2ed178acb438cc7de577 /test
parentc50e2851d2803bb37d9cdfa13f4a703812dc1e1c (diff)
* lib/thread.rb (SizedQueue#clear): wake waiting threads when called.
[Bug #9342] [ruby-core:59462] * test/thread/test_queue.rb: add a test for above. patched by Justin Collins. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/thread/test_queue.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index b0ffe0866d..9d8d481ba4 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -10,6 +10,28 @@ class TestQueue < Test::Unit::TestCase
grind(5, 1000, 15, SizedQueue, 1000)
end
+ def test_sized_queue_clear
+ # Fill queue, then test that SizedQueue#clear wakes up all waiting threads
+ sq = SizedQueue.new(2)
+ 2.times { sq << 1 }
+
+ t1 = Thread.new do
+ sq << 1
+ end
+
+ t2 = Thread.new do
+ sq << 1
+ end
+
+ t3 = Thread.new do
+ Thread.pass
+ sq.clear
+ end
+
+ [t3, t2, t1].each(&:join)
+ assert_equal sq.length, 2
+ end
+
def grind(num_threads, num_objects, num_iterations, klass, *args)
from_workers = klass.new(*args)
to_workers = klass.new(*args)