summaryrefslogtreecommitdiff
path: root/test
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
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')
-rw-r--r--test/-ext-/thread_fd_close/test_thread_fd_close.rb6
-rw-r--r--test/fiddle/test_func.rb10
-rw-r--r--test/fiddle/test_handle.rb18
-rw-r--r--test/fileutils/test_fileutils.rb1
-rw-r--r--test/net/imap/test_imap.rb1
-rw-r--r--test/openssl/test_ssl.rb10
-rw-r--r--test/readline/test_readline.rb10
-rw-r--r--test/rinda/test_rinda.rb54
-rw-r--r--test/ruby/test_continuation.rb9
-rw-r--r--test/ruby/test_exception.rb10
-rw-r--r--test/ruby/test_fiber.rb19
-rw-r--r--test/ruby/test_io.rb24
-rw-r--r--test/ruby/test_process.rb5
-rw-r--r--test/ruby/test_thread.rb82
-rw-r--r--test/rubygems/test_gem_request_connection_pools.rb13
-rw-r--r--test/socket/test_socket.rb6
-rw-r--r--test/thread/test_cv.rb10
-rw-r--r--test/thread/test_queue.rb33
-rw-r--r--test/thread/test_sync.rb8
19 files changed, 181 insertions, 148 deletions
diff --git a/test/-ext-/thread_fd_close/test_thread_fd_close.rb b/test/-ext-/thread_fd_close/test_thread_fd_close.rb
index c83b06d6726..e6c3895da71 100644
--- a/test/-ext-/thread_fd_close/test_thread_fd_close.rb
+++ b/test/-ext-/thread_fd_close/test_thread_fd_close.rb
@@ -9,7 +9,9 @@ class TestThreadFdClose < Test::Unit::TestCase
IO.pipe do |r, w|
th = Thread.new do
begin
- r.read(4)
+ assert_raise(IOError) {
+ r.read(4)
+ }
ensure
w.syswrite('done')
end
@@ -17,7 +19,7 @@ class TestThreadFdClose < Test::Unit::TestCase
Thread.pass until th.stop?
IO.thread_fd_close(r.fileno)
assert_equal 'done', r.read(4)
- assert_raise(IOError) { th.join }
+ th.join
end
end
end
diff --git a/test/fiddle/test_func.rb b/test/fiddle/test_func.rb
index 85179652232..8c35833a327 100644
--- a/test/fiddle/test_func.rb
+++ b/test/fiddle/test_func.rb
@@ -13,12 +13,12 @@ module Fiddle
def test_syscall_with_tainted_string
f = Function.new(@libc['system'], [TYPE_VOIDP], TYPE_INT)
- assert_raise(SecurityError) do
- Thread.new {
- $SAFE = 1
+ Thread.new {
+ $SAFE = 1
+ assert_raise(SecurityError) do
f.call("uname -rs".dup.taint)
- }.join
- end
+ end
+ }.join
end
def test_sinf
diff --git a/test/fiddle/test_handle.rb b/test/fiddle/test_handle.rb
index 444ac55da3e..77559eb4d96 100644
--- a/test/fiddle/test_handle.rb
+++ b/test/fiddle/test_handle.rb
@@ -9,20 +9,22 @@ module Fiddle
include Fiddle
def test_safe_handle_open
- t = Thread.new do
+ Thread.new do
$SAFE = 1
- Fiddle::Handle.new(LIBC_SO.dup.taint)
- end
- assert_raise(SecurityError) { t.value }
+ assert_raise(SecurityError) {
+ Fiddle::Handle.new(LIBC_SO.dup.taint)
+ }
+ end.join
end
def test_safe_function_lookup
- t = Thread.new do
+ Thread.new do
h = Fiddle::Handle.new(LIBC_SO)
$SAFE = 1
- h["qsort".dup.taint]
- end
- assert_raise(SecurityError) { t.value }
+ assert_raise(SecurityError) {
+ h["qsort".dup.taint]
+ }
+ end.join
end
def test_to_i
diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb
index 2b3978a7e69..584a1f517a2 100644
--- a/test/fileutils/test_fileutils.rb
+++ b/test/fileutils/test_fileutils.rb
@@ -235,6 +235,7 @@ class TestFileUtils < Test::Unit::TestCase
assert_raise(MiniTest::Assertion) {
Timeout.timeout(0.1) {
assert_output_lines([]) {
+ Thread.current.report_on_exception = false
raise "ok"
}
}
diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb
index 8e48317dab8..38ea84cc21f 100644
--- a/test/net/imap/test_imap.rb
+++ b/test/net/imap/test_imap.rb
@@ -660,6 +660,7 @@ EOF
}
ssl_server = OpenSSL::SSL::SSLServer.new(server, ctx)
ths = Thread.start do
+ Thread.current.report_on_exception = false # always join-ed
begin
sock = ssl_server.accept
begin
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index 1f7f6a39d1d..3b063d2e11b 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -1340,13 +1340,15 @@ end
ctx2.enable_fallback_scsv
ctx2.max_version = OpenSSL::SSL::TLS1_1_VERSION
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
- t = Thread.new { s2.connect }
- assert_raise_with_message(OpenSSL::SSL::SSLError, /inappropriate fallback/) {
- s1.accept
+ t = Thread.new {
+ assert_raise_with_message(OpenSSL::SSL::SSLError, /inappropriate fallback/) {
+ s2.connect
+ }
}
assert_raise_with_message(OpenSSL::SSL::SSLError, /inappropriate fallback/) {
- t.join
+ s1.accept
}
+ t.join
ensure
sock1.close
sock2.close
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 1d19af1e10e..68c1ff7312f 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -45,14 +45,14 @@ class TestReadline < Test::Unit::TestCase
assert_equal("> ", stdout.read(2))
assert_equal(1, Readline::HISTORY.length)
assert_equal("hello", Readline::HISTORY[0])
- assert_raise(SecurityError) do
- Thread.start {
- $SAFE = 1
+ Thread.start {
+ $SAFE = 1
+ assert_raise(SecurityError) do
replace_stdio(stdin.path, stdout.path) do
Readline.readline("> ".taint)
end
- }.join
- end
+ end
+ }.join
end
end
diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb
index 9874e328726..c899f32a8ab 100644
--- a/test/rinda/test_rinda.rb
+++ b/test/rinda/test_rinda.rb
@@ -241,17 +241,21 @@ module TupleSpaceTestModule
end
def test_ruby_talk_264062
- th = Thread.new { @ts.take([:empty], 1) }
+ th = Thread.new {
+ assert_raise(Rinda::RequestExpiredError) do
+ @ts.take([:empty], 1)
+ end
+ }
sleep(10)
- assert_raise(Rinda::RequestExpiredError) do
- thread_join(th)
- end
+ thread_join(th)
- th = Thread.new { @ts.read([:empty], 1) }
+ th = Thread.new {
+ assert_raise(Rinda::RequestExpiredError) do
+ @ts.read([:empty], 1)
+ end
+ }
sleep(10)
- assert_raise(Rinda::RequestExpiredError) do
- thread_join(th)
- end
+ thread_join(th)
end
def test_symbol_tuple
@@ -348,19 +352,18 @@ module TupleSpaceTestModule
template = nil
taker = Thread.new do
- @ts.take([:take, nil], 10) do |t|
- template = t
- Thread.new do
- template.cancel
- end
+ assert_raise(Rinda::RequestCanceledError) do
+ @ts.take([:take, nil], 10) do |t|
+ template = t
+ Thread.new do
+ template.cancel
+ end
+ end
end
end
sleep(2)
-
- assert_raise(Rinda::RequestCanceledError) do
- thread_join(taker)
- end
+ thread_join(taker)
assert(template.canceled?)
@@ -377,19 +380,18 @@ module TupleSpaceTestModule
template = nil
reader = Thread.new do
- @ts.read([:take, nil], 10) do |t|
- template = t
- Thread.new do
- template.cancel
- end
+ assert_raise(Rinda::RequestCanceledError) do
+ @ts.read([:take, nil], 10) do |t|
+ template = t
+ Thread.new do
+ template.cancel
+ end
+ end
end
end
sleep(2)
-
- assert_raise(Rinda::RequestCanceledError) do
- thread_join(reader)
- end
+ thread_join(reader)
assert(template.canceled?)
diff --git a/test/ruby/test_continuation.rb b/test/ruby/test_continuation.rb
index efc549b67a1..a06ac98c8c9 100644
--- a/test/ruby/test_continuation.rb
+++ b/test/ruby/test_continuation.rb
@@ -37,9 +37,11 @@ class TestContinuation < Test::Unit::TestCase
def test_error
cont = callcc{|c| c}
- assert_raise(RuntimeError){
- Thread.new{cont.call}.join
- }
+ Thread.new{
+ assert_raise(RuntimeError){
+ cont.call
+ }
+ }.join
assert_raise(LocalJumpError){
callcc
}
@@ -132,4 +134,3 @@ class TestContinuation < Test::Unit::TestCase
assert_equal 3, @memo
end
end
-
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index fab6ec9f0ff..3e9f4d1bc2a 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -183,12 +183,12 @@ class TestException < Test::Unit::TestCase
def test_throw_false
bug12743 = '[ruby-core:77229] [Bug #12743]'
- e = assert_raise_with_message(UncaughtThrowError, /false/, bug12743) {
- Thread.start {
+ Thread.start {
+ e = assert_raise_with_message(UncaughtThrowError, /false/, bug12743) {
throw false
- }.join
- }
- assert_same(false, e.tag, bug12743)
+ }
+ assert_same(false, e.tag, bug12743)
+ }.join
end
def test_else_no_exception
diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb
index 92c99612595..7b513a11fab 100644
--- a/test/ruby/test_fiber.rb
+++ b/test/ruby/test_fiber.rb
@@ -70,10 +70,12 @@ class TestFiber < Test::Unit::TestCase
assert_raise(ArgumentError){
Fiber.new # Fiber without block
}
- assert_raise(FiberError){
- f = Fiber.new{}
- Thread.new{f.resume}.join # Fiber yielding across thread
- }
+ f = Fiber.new{}
+ Thread.new{
+ assert_raise(FiberError){ # Fiber yielding across thread
+ f.resume
+ }
+ }.join
assert_raise(FiberError){
f = Fiber.new{}
f.resume
@@ -199,11 +201,11 @@ class TestFiber < Test::Unit::TestCase
end
def test_resume_root_fiber
- assert_raise(FiberError) do
- Thread.new do
+ Thread.new do
+ assert_raise(FiberError) do
Fiber.current.resume
- end.join
- end
+ end
+ end.join
end
def test_gc_root_fiber
@@ -377,4 +379,3 @@ class TestFiber < Test::Unit::TestCase
assert_match(/resumed/, Fiber.current.to_s)
end
end
-
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index f3b509a2613..009afc32971 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -3392,12 +3392,16 @@ __END__
str = ""
IO.pipe {|r,|
- t = Thread.new { r.read(nil, str) }
+ t = Thread.new {
+ assert_raise(RuntimeError) {
+ r.read(nil, str)
+ }
+ }
sleep 0.1 until t.stop?
t.raise
sleep 0.1 while t.alive?
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
- assert_raise(RuntimeError) { t.join }
+ t.join
}
end if /cygwin/ !~ RUBY_PLATFORM
@@ -3406,12 +3410,16 @@ __END__
str = ""
IO.pipe {|r, w|
- t = Thread.new { r.readpartial(4096, str) }
+ t = Thread.new {
+ assert_raise(RuntimeError) {
+ r.readpartial(4096, str)
+ }
+ }
sleep 0.1 until t.stop?
t.raise
sleep 0.1 while t.alive?
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
- assert_raise(RuntimeError) { t.join }
+ t.join
}
end if /cygwin/ !~ RUBY_PLATFORM
@@ -3431,12 +3439,16 @@ __END__
str = ""
IO.pipe {|r, w|
- t = Thread.new { r.sysread(4096, str) }
+ t = Thread.new {
+ assert_raise(RuntimeError) {
+ r.sysread(4096, str)
+ }
+ }
sleep 0.1 until t.stop?
t.raise
sleep 0.1 while t.alive?
assert_nothing_raised(RuntimeError, bug8669) { str.clear }
- assert_raise(RuntimeError) { t.join }
+ t.join
}
end if /cygwin/ !~ RUBY_PLATFORM
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index e4c7bc9190d..58644832d3b 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1580,7 +1580,10 @@ class TestProcess < Test::Unit::TestCase
pid = nil
IO.pipe do |r, w|
pid = fork { r.read(1); exit }
- Thread.start { raise }
+ Thread.start {
+ Thread.current.report_on_exception = false
+ raise
+ }
w.puts
end
Process.wait pid
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index ed22249091a..1e3e760a4d5 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -448,7 +448,10 @@ class TestThread < Test::Unit::TestCase
end
def test_status_and_stop_p
- a = ::Thread.new { raise("die now") }
+ a = ::Thread.new {
+ Thread.current.report_on_exception = false
+ raise("die now")
+ }
b = Thread.new { Thread.stop }
c = Thread.new { Thread.exit }
e = Thread.current
@@ -560,13 +563,13 @@ class TestThread < Test::Unit::TestCase
end
def test_thread_local_security
- assert_raise(FrozenError) do
- Thread.new do
- Thread.current[:foo] = :bar
- Thread.current.freeze
+ Thread.new do
+ Thread.current[:foo] = :bar
+ Thread.current.freeze
+ assert_raise(FrozenError) do
Thread.current[:foo] = :baz
- end.join
- end
+ end
+ end.join
end
def test_thread_local_dynamic_symbol
@@ -615,11 +618,11 @@ class TestThread < Test::Unit::TestCase
def test_mutex_illegal_unlock
m = Thread::Mutex.new
m.lock
- assert_raise(ThreadError) do
- Thread.new do
+ Thread.new do
+ assert_raise(ThreadError) do
m.unlock
- end.join
- end
+ end
+ end.join
end
def test_mutex_fifo_like_lock
@@ -767,12 +770,12 @@ class TestThread < Test::Unit::TestCase
r=:ng
e=Class.new(Exception)
th_s = Thread.current
- begin
- th = Thread.start{
+ th = Thread.start{
+ assert_raise(RuntimeError) {
Thread.handle_interrupt(Object => :on_blocking){
begin
Thread.pass until r == :wait
- Thread.current.raise RuntimeError
+ Thread.current.raise RuntimeError, "will raise in sleep"
r = :ok
sleep
ensure
@@ -780,11 +783,9 @@ class TestThread < Test::Unit::TestCase
end
}
}
- assert_raise(e) {r = :wait; sleep 0.2}
- assert_raise(RuntimeError) {th.join(0.2)}
- ensure
- th.kill
- end
+ }
+ assert_raise(e) {r = :wait; sleep 0.2}
+ assert_not_equal nil, th.join
assert_equal(:ok,r)
end
@@ -971,11 +972,11 @@ _eom
end
def test_thread_join_main_thread
- assert_raise(ThreadError) do
- Thread.new(Thread.current) {|t|
+ Thread.new(Thread.current) {|t|
+ assert_raise(ThreadError) do
t.join
- }.join
- end
+ end
+ }.join
end
def test_main_thread_status_at_exit
@@ -1019,31 +1020,30 @@ q.pop
ary = []
t = Thread.new {
- begin
- ary << Thread.current.status
- sleep #1
- ensure
+ assert_raise(RuntimeError) do
begin
ary << Thread.current.status
- sleep #2
+ sleep #1
ensure
- ary << Thread.current.status
+ begin
+ ary << Thread.current.status
+ sleep #2
+ ensure
+ ary << Thread.current.status
+ end
end
end
}
- begin
- Thread.pass until ary.size >= 1
- Thread.pass until t.stop?
- t.kill # wake up sleep #1
- Thread.pass until ary.size >= 2
- Thread.pass until t.stop?
- t.raise "wakeup" # wake up sleep #2
- Thread.pass while t.alive?
- assert_equal(ary, ["run", "aborting", "aborting"])
- ensure
- t.join rescue nil
- end
+ Thread.pass until ary.size >= 1
+ Thread.pass until t.stop?
+ t.kill # wake up sleep #1
+ Thread.pass until ary.size >= 2
+ Thread.pass until t.stop?
+ t.raise "wakeup" # wake up sleep #2
+ Thread.pass while t.alive?
+ assert_equal(ary, ["run", "aborting", "aborting"])
+ t.join
end
def test_mutex_owned
diff --git a/test/rubygems/test_gem_request_connection_pools.rb b/test/rubygems/test_gem_request_connection_pools.rb
index a9bddb900e5..a087095a53c 100644
--- a/test/rubygems/test_gem_request_connection_pools.rb
+++ b/test/rubygems/test_gem_request_connection_pools.rb
@@ -118,13 +118,12 @@ class TestGemRequestConnectionPool < Gem::TestCase
pool.checkout
- t1 = Thread.new {
- Timeout.timeout(1) do
- pool.checkout
+ Thread.new {
+ assert_raises(Timeout::Error) do
+ Timeout.timeout(1) do
+ pool.checkout
+ end
end
- }
- assert_raises(Timeout::Error) do
- t1.join
- end
+ }.join
end
end
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index 5ee09f8e9d0..126f7894926 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -536,13 +536,15 @@ class TestSocket < Test::Unit::TestCase
begin sleep(0.1) end until serv_thread.stop?
sock = TCPSocket.new("localhost", server.addr[1])
client_thread = Thread.new do
- sock.readline
+ assert_raise(IOError, bug4390) {
+ sock.readline
+ }
end
begin sleep(0.1) end until client_thread.stop?
Timeout.timeout(1) do
sock.close
sock = nil
- assert_raise(IOError, bug4390) {client_thread.join}
+ client_thread.join
end
ensure
serv_thread.value.close
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, [])