summaryrefslogtreecommitdiff
path: root/test/thread
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 18:44:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 18:44:49 +0000
commit15689ed7780b06ddc14cde4f427de834177283a5 (patch)
treebed64f4fdaf3e1a140642bdd0354384ae286759c /test/thread
parent967eab83e333430600926366621aa3a978701c6a (diff)
Fix test-all tests to avoid creating report_on_exception warnings
* The warnings are shown by Thread.report_on_exception defaulting to true. [Feature #14143] [ruby-core:83979] * Improves tests by narrowing down the scope where an exception is expected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/thread')
-rw-r--r--test/thread/test_cv.rb10
-rw-r--r--test/thread/test_queue.rb33
-rw-r--r--test/thread/test_sync.rb8
3 files changed, 28 insertions, 23 deletions
diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb
index 702462606dd..1e15d2e9ec3 100644
--- a/test/thread/test_cv.rb
+++ b/test/thread/test_cv.rb
@@ -42,12 +42,10 @@ class TestConditionVariable < Test::Unit::TestCase
thread = Thread.new do
Thread.current.abort_on_exception = false
mutex.synchronize do
- begin
+ assert_raise(Interrupt) {
condvar.wait(mutex)
- rescue Exception
- locked = mutex.locked?
- raise
- end
+ }
+ locked = mutex.locked?
end
end
@@ -56,7 +54,7 @@ class TestConditionVariable < Test::Unit::TestCase
end
thread.raise Interrupt, "interrupt a dead condition variable"
- assert_raise(Interrupt) { thread.value }
+ thread.join
assert(locked)
end
diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb
index 56cded8a2f5..4e6c9fa4c9f 100644
--- a/test/thread/test_queue.rb
+++ b/test/thread/test_queue.rb
@@ -373,7 +373,12 @@ class TestQueue < Test::Unit::TestCase
def test_blocked_pushers
q = SizedQueue.new 3
prod_threads = 6.times.map do |i|
- thr = Thread.new{q << i}; thr[:pc] = i; thr
+ thr = Thread.new{
+ Thread.current.report_on_exception = false
+ q << i
+ }
+ thr[:pc] = i
+ thr
end
# wait until some producer threads have finished, and the other 3 are blocked
@@ -413,25 +418,20 @@ class TestQueue < Test::Unit::TestCase
def test_deny_pushers
[->{Queue.new}, ->{SizedQueue.new 3}].each do |qcreate|
- prod_threads = nil
q = qcreate[]
synq = Queue.new
- producers_start = Thread.new do
- prod_threads = 20.times.map do |i|
- Thread.new{ synq.pop; q << i }
- end
+ prod_threads = 20.times.map do |i|
+ Thread.new {
+ synq.pop
+ assert_raise(ClosedQueueError) {
+ q << i
+ }
+ }
end
q.close
synq.close # start producer threads
- # wait for all threads to be finished, because of exceptions
- # NOTE: thr.status will be nil (raised) or false (terminated)
- sleep 0.01 until prod_threads&.all?{|thr| !thr.status}
-
- # check that all threads failed to call push
- prod_threads.each do |thr|
- assert_kind_of ClosedQueueError, (thr.value rescue $!)
- end
+ prod_threads.each(&:join)
end
end
@@ -451,7 +451,10 @@ class TestQueue < Test::Unit::TestCase
def test_blocked_pushers_empty
q = SizedQueue.new 3
prod_threads = 6.times.map do |i|
- Thread.new{ q << i}
+ Thread.new{
+ Thread.current.report_on_exception = false
+ q << i
+ }
end
# this ensures that all producer threads call push before close
diff --git a/test/thread/test_sync.rb b/test/thread/test_sync.rb
index e576fc1d323..8241445faff 100644
--- a/test/thread/test_sync.rb
+++ b/test/thread/test_sync.rb
@@ -52,11 +52,15 @@ class SyncTest < Test::Unit::TestCase
tester= Tester.new
tester.sync_lock(:EX)
- t = Thread.new { tester.sync_lock(:EX) }
+ t = Thread.new {
+ assert_raise(RuntimeError) {
+ tester.sync_lock(:EX)
+ }
+ }
sleep 0.1 until t.stop?
t.raise
- sleep 0.1 while t.alive?
+ t.join
assert_equal(tester.sync_waiting.uniq, tester.sync_waiting)
assert_equal(tester.sync_waiting, [])