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.rb84
1 files changed, 11 insertions, 73 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index fd77853f0e..3fa0eae2c1 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -8,13 +8,13 @@ class TestThreadQueue < Test::Unit::TestCase
SizedQueue = Thread::SizedQueue
def test_queue_initialized
- assert_raise_with_message(TypeError, /\bQueue.* not initialized/) {
+ assert_raise(TypeError) {
Queue.allocate.push(nil)
}
end
def test_sized_queue_initialized
- assert_raise_with_message(TypeError, /\bSizedQueue.* not initialized/) {
+ assert_raise(TypeError) {
SizedQueue.allocate.push(nil)
}
end
@@ -111,23 +111,6 @@ class TestThreadQueue < Test::Unit::TestCase
assert_equal(0, q.num_waiting)
end
- def test_queue_pop_timeout
- q = Thread::Queue.new
- q << 1
- assert_equal 1, q.pop(timeout: 1)
-
- t1 = Thread.new { q.pop(timeout: 1) }
- assert_equal t1, t1.join(2)
- assert_nil t1.value
-
- t2 = Thread.new { q.pop(timeout: 0.1) }
- assert_equal t2, t2.join(1)
- assert_nil t2.value
- ensure
- t1&.kill&.join
- t2&.kill&.join
- end
-
def test_queue_pop_non_block
q = Thread::Queue.new
assert_raise_with_message(ThreadError, /empty/) do
@@ -143,24 +126,6 @@ class TestThreadQueue < Test::Unit::TestCase
assert_equal(0, q.num_waiting)
end
- def test_sized_queue_pop_timeout
- q = Thread::SizedQueue.new(1)
-
- q << 1
- assert_equal 1, q.pop(timeout: 1)
-
- t1 = Thread.new { q.pop(timeout: 1) }
- assert_equal t1, t1.join(2)
- assert_nil t1.value
-
- t2 = Thread.new { q.pop(timeout: 0.1) }
- assert_equal t2, t2.join(1)
- assert_nil t2.value
- ensure
- t1&.kill&.join
- t2&.kill&.join
- end
-
def test_sized_queue_pop_non_block
q = Thread::SizedQueue.new(1)
assert_raise_with_message(ThreadError, /empty/) do
@@ -168,24 +133,6 @@ class TestThreadQueue < Test::Unit::TestCase
end
end
- def test_sized_queue_push_timeout
- q = Thread::SizedQueue.new(1)
-
- q << 1
- assert_equal 1, q.size
-
- t1 = Thread.new { q.push(2, timeout: 1) }
- assert_equal t1, t1.join(2)
- assert_nil t1.value
-
- t2 = Thread.new { q.push(2, timeout: 0.1) }
- assert_equal t2, t2.join(1)
- assert_nil t2.value
- ensure
- t1&.kill&.join
- t2&.kill&.join
- end
-
def test_sized_queue_push_interrupt
q = Thread::SizedQueue.new(1)
q.push(1)
@@ -204,18 +151,16 @@ class TestThreadQueue < Test::Unit::TestCase
end
def test_thr_kill
- omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM
-
bug5343 = '[ruby-core:39634]'
Dir.mktmpdir {|d|
- timeout = 60
+ timeout = EnvUtil.apply_timeout_scale(60)
total_count = 250
begin
- assert_normal_exit(<<-"_eom", bug5343, timeout: timeout, chdir: d)
- r, w = IO.pipe
+ assert_normal_exit(<<-"_eom", bug5343, **{:timeout => timeout, :chdir=>d})
#{total_count}.times do |i|
- File.open("test_thr_kill_count", "w") {|f| f.puts i }
+ 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,14 +530,9 @@ 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
- mutex.lock
- mutex.unlock
+ sleep(rand / 100)
count_items.times{|i| q << [i,"#{i} for #{Thread.current.inspect}"]}
end
end
@@ -610,11 +550,9 @@ 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.to_s =~ /\A(?:run|sleep)\z/}
-
- assert (consumers + producers).all?{|thr| thr.status.to_s =~ /\A(?:run|sleep)\z/}, 'no threads running'
+ Thread.pass until Time.now - t > 10 || (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/}
- mutex.unlock
+ assert (consumers + producers).all?{|thr| thr.status =~ /\A(?:run|sleep)\z/}, 'no threads running'
# just exercising the concurrency of the support methods.
counter = Thread.new do
@@ -642,10 +580,10 @@ class TestThreadQueue < Test::Unit::TestCase
def test_queue_with_trap
if ENV['APPVEYOR'] == 'True' && RUBY_PLATFORM.match?(/mswin/)
- omit 'This test fails too often on AppVeyor vs140'
+ skip 'This test fails too often on AppVeyor vs140'
end
if RUBY_PLATFORM.match?(/mingw/)
- omit 'This test fails too often on MinGW'
+ skip 'This test fails too often on MinGW'
end
assert_in_out_err([], <<-INPUT, %w(INT INT exit), [])