Skip to content

Commit

Permalink
Fix test-all tests to avoid creating report_on_exception warnings
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eregon committed Dec 12, 2017
1 parent 967eab8 commit 15689ed
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 148 deletions.
6 changes: 4 additions & 2 deletions test/-ext-/thread_fd_close/test_thread_fd_close.rb
Expand Up @@ -9,15 +9,17 @@ def test_thread_fd_close
IO.pipe do |r, w|
th = Thread.new do
begin
r.read(4)
assert_raise(IOError) {
r.read(4)
}
ensure
w.syswrite('done')
end
end
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
10 changes: 5 additions & 5 deletions test/fiddle/test_func.rb
Expand Up @@ -13,12 +13,12 @@ def test_random

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
Expand Down
18 changes: 10 additions & 8 deletions test/fiddle/test_handle.rb
Expand Up @@ -9,20 +9,22 @@ class TestHandle < TestCase
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
Expand Down
1 change: 1 addition & 0 deletions test/fileutils/test_fileutils.rb
Expand Up @@ -235,6 +235,7 @@ def test_assert_output_lines
assert_raise(MiniTest::Assertion) {
Timeout.timeout(0.1) {
assert_output_lines([]) {
Thread.current.report_on_exception = false
raise "ok"
}
}
Expand Down
1 change: 1 addition & 0 deletions test/net/imap/test_imap.rb
Expand Up @@ -660,6 +660,7 @@ def imaps_test
}
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
Expand Down
10 changes: 6 additions & 4 deletions test/openssl/test_ssl.rb
Expand Up @@ -1340,13 +1340,15 @@ def test_fallback_scsv
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
Expand Down
10 changes: 5 additions & 5 deletions test/readline/test_readline.rb
Expand Up @@ -45,14 +45,14 @@ def test_readline
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

Expand Down
54 changes: 28 additions & 26 deletions test/rinda/test_rinda.rb
Expand Up @@ -241,17 +241,21 @@ def test_inp_rdp
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
Expand Down Expand Up @@ -348,19 +352,18 @@ def test_cancel_01

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?)

Expand All @@ -377,19 +380,18 @@ def test_cancel_02

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?)

Expand Down
9 changes: 5 additions & 4 deletions test/ruby/test_continuation.rb
Expand Up @@ -37,9 +37,11 @@ def test_check_localvars

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
}
Expand Down Expand Up @@ -132,4 +134,3 @@ def test_tracing_with_thread_set_trace_func
assert_equal 3, @memo
end
end

10 changes: 5 additions & 5 deletions test/ruby/test_exception.rb
Expand Up @@ -183,12 +183,12 @@ def test_catch_throw_in_require

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
Expand Down
19 changes: 10 additions & 9 deletions test/ruby/test_fiber.rb
Expand Up @@ -70,10 +70,12 @@ def test_error
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
Expand Down Expand Up @@ -199,11 +201,11 @@ def test_fiber_transfer_segv
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
Expand Down Expand Up @@ -377,4 +379,3 @@ def test_to_s
assert_match(/resumed/, Fiber.current.to_s)
end
end

24 changes: 18 additions & 6 deletions test/ruby/test_io.rb
Expand Up @@ -3392,12 +3392,16 @@ def test_read_unlocktmp_ensure

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

Expand All @@ -3406,12 +3410,16 @@ def test_readpartial_unlocktmp_ensure

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

Expand All @@ -3431,12 +3439,16 @@ def test_sysread_unlocktmp_ensure

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

Expand Down
5 changes: 4 additions & 1 deletion test/ruby/test_process.rb
Expand Up @@ -1580,7 +1580,10 @@ def test_wait_and_sigchild
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
Expand Down

0 comments on commit 15689ed

Please sign in to comment.