summaryrefslogtreecommitdiff
path: root/test/ruby/test_thread_queue.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_thread_queue.rb')
-rw-r--r--test/ruby/test_thread_queue.rb34
1 files changed, 25 insertions, 9 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index 723450ad23..545bf98888 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -8,17 +8,26 @@ class TestThreadQueue < Test::Unit::TestCase
SizedQueue = Thread::SizedQueue
def test_queue_initialized
- assert_raise(TypeError) {
+ assert_raise_with_message(TypeError, /\bQueue.* not initialized/) {
Queue.allocate.push(nil)
}
end
def test_sized_queue_initialized
- assert_raise(TypeError) {
+ assert_raise_with_message(TypeError, /\bSizedQueue.* not initialized/) {
SizedQueue.allocate.push(nil)
}
end
+ def test_freeze
+ assert_raise(TypeError) {
+ Queue.new.freeze
+ }
+ assert_raise(TypeError) {
+ SizedQueue.new(5).freeze
+ }
+ end
+
def test_queue
grind(5, 1000, 15, Queue)
end
@@ -208,14 +217,14 @@ class TestThreadQueue < Test::Unit::TestCase
bug5343 = '[ruby-core:39634]'
Dir.mktmpdir {|d|
- timeout = EnvUtil.apply_timeout_scale(60)
+ timeout = 60
total_count = 250
begin
- assert_normal_exit(<<-"_eom", bug5343, **{:timeout => timeout, :chdir=>d})
+ assert_normal_exit(<<-"_eom", bug5343, timeout: timeout, chdir: d)
+ r, w = IO.pipe
#{total_count}.times do |i|
- open("test_thr_kill_count", "w") {|f| f.puts i }
+ File.open("test_thr_kill_count", "w") {|f| f.puts i }
queue = Thread::Queue.new
- r, w = IO.pipe
th = Thread.start {
queue.push(nil)
r.read 1
@@ -585,9 +594,14 @@ class TestThreadQueue < Test::Unit::TestCase
count_items = rand(3000..5000)
count_producers = rand(10..20)
+ # ensure threads do not start running too soon and complete before we check status
+ mutex = Mutex.new
+ mutex.lock
+
producers = count_producers.times.map do
Thread.new do
- sleep(rand / 100)
+ mutex.lock
+ mutex.unlock
count_items.times{|i| q << [i,"#{i} for #{Thread.current.inspect}"]}
end
end
@@ -605,9 +619,11 @@ class TestThreadQueue < Test::Unit::TestCase
# No dead or finished threads, give up to 10 seconds to start running
t = Time.now
- Thread.pass until Time.now - t > 10 || (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/}
+ Thread.pass until Time.now - t > 10 || (consumers + producers).all?{|thr| thr.status.to_s =~ /\A(?:run|sleep)\z/}
+
+ assert (consumers + producers).all?{|thr| thr.status.to_s =~ /\A(?:run|sleep)\z/}, 'no threads running'
- assert (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/}, 'no threads running'
+ mutex.unlock
# just exercising the concurrency of the support methods.
counter = Thread.new do