From 74b9f78e11b915439555290dc3bdd4331303561c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Mar 2012 06:05:06 +0000 Subject: [PATCH] test/*: remove assert_nothing_raised It makes test failures hard to track down, tests will already fail if exceptions are thrown and we'll get nice backtraces. --- test/lib_read_write.rb | 19 +++++++------------ test/test_accept_class.rb | 10 +++++----- test/test_autopush.rb | 22 +++++++++------------- test/test_connect_fd_leak.rb | 10 ++++------ test/test_poll.rb | 4 +--- test/test_singleton_read_write.rb | 2 +- test/test_tryopen.rb | 2 +- 7 files changed, 28 insertions(+), 41 deletions(-) diff --git a/test/lib_read_write.rb b/test/lib_read_write.rb index d7f50c2..dfcba20 100644 --- a/test/lib_read_write.rb +++ b/test/lib_read_write.rb @@ -9,10 +9,8 @@ module LibReadWriteTest RANDOM_BLOB = File.open("/dev/urandom") { |fp| fp.read(10 * 1024 * 1024) } def teardown - assert_nothing_raised do - @rd.close if defined?(@rd) && ! @rd.closed? - @wr.close if defined?(@wr) && ! @wr.closed? - end + @rd.close if defined?(@rd) && ! @rd.closed? + @wr.close if defined?(@wr) && ! @wr.closed? end def test_write_empty @@ -264,10 +262,8 @@ module LibReadWriteTest foo = nil t0 = Time.now thr = Thread.new { sleep 1; @wr.write "HELLO" } - assert_nothing_raised do - foo = @rd.kgio_read(5) - elapsed = Time.now - t0 - end + foo = @rd.kgio_read(5) + elapsed = Time.now - t0 assert elapsed >= 1.0, "elapsed: #{elapsed}" assert_equal "HELLO", foo thr.join @@ -286,10 +282,9 @@ module LibReadWriteTest foo = nil t0 = Time.now thr = Thread.new { sleep 1; @rd.readpartial(nr) } - assert_nothing_raised do - foo = @wr.kgio_write("HELLO") - elapsed = Time.now - t0 - end + foo = @wr.kgio_write("HELLO") + elapsed = Time.now - t0 + assert_nil foo if @wr.stat.pipe? assert elapsed >= 1.0, "elapsed: #{elapsed}" diff --git a/test/test_accept_class.rb b/test/test_accept_class.rb index cf59a2f..0e1d172 100644 --- a/test/test_accept_class.rb +++ b/test/test_accept_class.rb @@ -12,12 +12,12 @@ class TestAcceptClass < Test::Unit::TestCase end def teardown - assert_nothing_raised { Kgio.accept_class = nil } + Kgio.accept_class = nil assert_equal Kgio::Socket, Kgio.accept_class end def test_tcp_socket - assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket } + Kgio.accept_class = Kgio::TCPSocket assert_equal Kgio::TCPSocket, Kgio.accept_class end @@ -31,21 +31,21 @@ class TestAcceptClass < Test::Unit::TestCase @srv = Kgio::TCPServer.new(@host, 0) @port = @srv.addr[1] - assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket } + Kgio.accept_class = Kgio::TCPSocket client = TCPSocket.new(@host, @port) assert_instance_of Kgio::TCPSocket, @srv.kgio_accept client = TCPSocket.new(@host, @port) IO.select([@srv]) assert_instance_of Kgio::TCPSocket, @srv.kgio_tryaccept - assert_nothing_raised { Kgio.accept_class = nil } + Kgio.accept_class = nil client = TCPSocket.new(@host, @port) assert_instance_of Kgio::Socket, @srv.kgio_accept client = TCPSocket.new(@host, @port) IO.select([@srv]) assert_instance_of Kgio::Socket, @srv.kgio_tryaccept - assert_nothing_raised { Kgio.accept_class = Kgio::UNIXSocket } + Kgio.accept_class = Kgio::UNIXSocket client = TCPSocket.new(@host, @port) assert_instance_of Kgio::UNIXSocket, @srv.kgio_accept client = TCPSocket.new(@host, @port) diff --git a/test/test_autopush.rb b/test/test_autopush.rb index 57fbefa..6c6e05f 100644 --- a/test/test_autopush.rb +++ b/test/test_autopush.rb @@ -18,12 +18,10 @@ class TestAutopush < Test::Unit::TestCase @host = ENV["TEST_HOST"] || '127.0.0.1' @srv = Kgio::TCPServer.new(@host, 0) - assert_nothing_raised { + RUBY_PLATFORM =~ /linux/ and @srv.setsockopt(Socket::IPPROTO_TCP, TCP_CORK, 1) - } if RUBY_PLATFORM =~ /linux/ - assert_nothing_raised { + RUBY_PLATFORM =~ /freebsd/ and @srv.setsockopt(Socket::IPPROTO_TCP, TCP_NOPUSH, 1) - } if RUBY_PLATFORM =~ /freebsd/ @port = @srv.addr[1] end @@ -35,7 +33,7 @@ class TestAutopush < Test::Unit::TestCase assert ! s.kgio_autopush? s.kgio_autopush = true assert s.kgio_autopush? - assert_nothing_raised { s.kgio_write 'asdf' } + s.kgio_write 'asdf' assert_equal :wait_readable, s.kgio_tryread(1) assert s.kgio_autopush? val = s.getsockopt(Socket::IPPROTO_TCP, opt).unpack('i')[0] @@ -64,12 +62,10 @@ class TestAutopush < Test::Unit::TestCase lines = io.readlines assert lines.grep(/TCP_CORK/).empty?, lines.inspect else - assert_nothing_raised do - @wr = @srv.kgio_accept - t0 = Time.now - @wr.kgio_write "HI\n" - rc = @wr.kgio_tryread 666 - end + @wr = @srv.kgio_accept + t0 = Time.now + @wr.kgio_write "HI\n" + rc = @wr.kgio_tryread 666 end assert_equal "HI\n", @rd.kgio_read(3) diff = Time.now - t0 @@ -151,8 +147,8 @@ class TestAutopush < Test::Unit::TestCase lines = io.readlines assert_equal 2, lines.grep(/TCP_CORK/).size, lines.inspect end - assert_nothing_raised { @wr.close } - assert_nothing_raised { @rd.close } + @wr.close + @rd.close @wr = Kgio::TCPSocket.new(@host, @port) if defined?(Strace) diff --git a/test/test_connect_fd_leak.rb b/test/test_connect_fd_leak.rb index f6a8543..1dfc4cd 100644 --- a/test/test_connect_fd_leak.rb +++ b/test/test_connect_fd_leak.rb @@ -9,11 +9,9 @@ class TestConnectFDLeak < Test::Unit::TestCase nr = 0 path = "/non/existent/path" assert(! File.exist?(path), "#{path} should not exist") - assert_nothing_raised do - begin - sock = Kgio::UNIXSocket.new(path) - rescue Errno::ENOENT - end while (nr += 1) < 10000 - end + begin + sock = Kgio::UNIXSocket.new(path) + rescue Errno::ENOENT + end while (nr += 1) < 10000 end end diff --git a/test/test_poll.rb b/test/test_poll.rb index df59354..40092cf 100644 --- a/test/test_poll.rb +++ b/test/test_poll.rb @@ -122,9 +122,7 @@ class TestPoll < Test::Unit::TestCase exit!(0) end - assert_nothing_raised do - empty += 1 until Kgio.poll(set.dup, 100) - end + empty += 1 until Kgio.poll(set.dup, 100) _, status = Process.waitpid2(pid) assert status.success?, status.inspect assert usr1 > 0, "usr1: #{usr1}" diff --git a/test/test_singleton_read_write.rb b/test/test_singleton_read_write.rb index 5abbf00..86d30a2 100644 --- a/test/test_singleton_read_write.rb +++ b/test/test_singleton_read_write.rb @@ -6,7 +6,7 @@ class TestSingletonReadWrite < Test::Unit::TestCase def test_unix_socketpair a, b = UNIXSocket.pair - assert_nothing_raised { Kgio.trywrite(a, "HELLO") } + Kgio.trywrite(a, "HELLO") buf = "" assert_equal "HELLO", Kgio.tryread(b, 5, buf) assert_equal "HELLO", buf diff --git a/test/test_tryopen.rb b/test/test_tryopen.rb index 5a8efb2..80b5de3 100644 --- a/test/test_tryopen.rb +++ b/test/test_tryopen.rb @@ -15,7 +15,7 @@ class TestTryopen < Test::Unit::TestCase assert_equal File.read(__FILE__), tmp.read assert_equal __FILE__, tmp.path assert_equal __FILE__, tmp.to_path - assert_nothing_raised { tmp.close } + tmp.close end def test_tryopen_ENOENT -- 2.11.4.GIT