From f4af812a28b03508c96853739aea53f7a6714abf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 13 Nov 2012 20:22:13 +0000 Subject: tests: remove assert_nothing_raised (part 2) assert_nothing_raised ends up hiding errors and backtraces, making things harder to debug. Since Test::Unit already fails on uncaught exceptions, there is no need to assert on the lack of exceptions for a successful test run. This is a followup to commit 5acf5522295c947d3118926d1a1077007f615de9 --- test/test_helper.rb | 31 +++++----- test/unit/test_configurator.rb | 21 +++---- test/unit/test_http_parser.rb | 10 +--- test/unit/test_http_parser_ng.rb | 12 ++-- test/unit/test_request.rb | 63 ++++++++------------- test/unit/test_server.rb | 119 ++++++++++++++++----------------------- test/unit/test_signals.rb | 93 ++++++++++++------------------ test/unit/test_socket_helper.rb | 29 ++++------ test/unit/test_stream_input.rb | 9 ++- test/unit/test_tee_input.rb | 24 ++++---- test/unit/test_upload.rb | 2 +- 11 files changed, 166 insertions(+), 247 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 11dd5ee..cf98996 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -155,9 +155,8 @@ end def assert_shutdown(pid) wait_master_ready("test_stderr.#{pid}.log") - assert_nothing_raised { Process.kill(:QUIT, pid) } - status = nil - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + Process.kill(:QUIT, pid) + pid, status = Process.waitpid2(pid) assert status.success?, "exited successfully" end @@ -191,8 +190,8 @@ end def reexec_usr2_quit_test(pid, pid_file) assert File.exist?(pid_file), "pid file OK" assert ! File.exist?("#{pid_file}.oldbin"), "oldbin pid file" - assert_nothing_raised { Process.kill(:USR2, pid) } - assert_nothing_raised { retry_hit(["http://#{@addr}:#{@port}/"]) } + Process.kill(:USR2, pid) + retry_hit(["http://#{@addr}:#{@port}/"]) wait_for_file("#{pid_file}.oldbin") wait_for_file(pid_file) @@ -202,35 +201,33 @@ def reexec_usr2_quit_test(pid, pid_file) # kill old master process assert_not_equal pid, new_pid assert_equal pid, old_pid - assert_nothing_raised { Process.kill(:QUIT, old_pid) } - assert_nothing_raised { retry_hit(["http://#{@addr}:#{@port}/"]) } + Process.kill(:QUIT, old_pid) + retry_hit(["http://#{@addr}:#{@port}/"]) wait_for_death(old_pid) assert_equal new_pid, File.read(pid_file).to_i - assert_nothing_raised { retry_hit(["http://#{@addr}:#{@port}/"]) } - assert_nothing_raised { Process.kill(:QUIT, new_pid) } + retry_hit(["http://#{@addr}:#{@port}/"]) + Process.kill(:QUIT, new_pid) end def reexec_basic_test(pid, pid_file) results = retry_hit(["http://#{@addr}:#{@port}/"]) assert_equal String, results[0].class - assert_nothing_raised { Process.kill(0, pid) } + Process.kill(0, pid) master_log = "#{@tmpdir}/test_stderr.#{pid}.log" wait_master_ready(master_log) File.truncate(master_log, 0) nr = 50 kill_point = 2 - assert_nothing_raised do - nr.times do |i| - hit(["http://#{@addr}:#{@port}/#{i}"]) - i == kill_point and Process.kill(:HUP, pid) - end + nr.times do |i| + hit(["http://#{@addr}:#{@port}/#{i}"]) + i == kill_point and Process.kill(:HUP, pid) end wait_master_ready(master_log) assert File.exist?(pid_file), "pid=#{pid_file} exists" new_pid = File.read(pid_file).to_i assert_not_equal pid, new_pid - assert_nothing_raised { Process.kill(0, new_pid) } - assert_nothing_raised { Process.kill(:QUIT, new_pid) } + Process.kill(0, new_pid) + Process.kill(:QUIT, new_pid) end def wait_for_file(path) diff --git a/test/unit/test_configurator.rb b/test/unit/test_configurator.rb index c19c427..267eea3 100644 --- a/test/unit/test_configurator.rb +++ b/test/unit/test_configurator.rb @@ -9,7 +9,7 @@ TestStruct = Struct.new( class TestConfigurator < Test::Unit::TestCase def test_config_init - assert_nothing_raised { Unicorn::Configurator.new {} } + Unicorn::Configurator.new {} end def test_expand_addr @@ -66,7 +66,7 @@ class TestConfigurator < Test::Unit::TestCase def test_config_defaults cfg = Unicorn::Configurator.new(:use_defaults => true) test_struct = TestStruct.new - assert_nothing_raised { cfg.commit!(test_struct) } + cfg.commit!(test_struct) Unicorn::Configurator::DEFAULTS.each do |key,value| assert_equal value, test_struct.__send__(key) end @@ -76,7 +76,7 @@ class TestConfigurator < Test::Unit::TestCase cfg = Unicorn::Configurator.new(:use_defaults => true) skip = [ :logger ] test_struct = TestStruct.new - assert_nothing_raised { cfg.commit!(test_struct, :skip => skip) } + cfg.commit!(test_struct, :skip => skip) Unicorn::Configurator::DEFAULTS.each do |key,value| next if skip.include?(key) assert_equal value, test_struct.__send__(key) @@ -89,12 +89,9 @@ class TestConfigurator < Test::Unit::TestCase expect = { :sndbuf => 1, :rcvbuf => 2, :backlog => 10 }.freeze listener = "127.0.0.1:12345" tmp.syswrite("listen '#{listener}', #{expect.inspect}\n") - cfg = nil - assert_nothing_raised do - cfg = Unicorn::Configurator.new(:config_file => tmp.path) - end + cfg = Unicorn::Configurator.new(:config_file => tmp.path) test_struct = TestStruct.new - assert_nothing_raised { cfg.commit!(test_struct) } + cfg.commit!(test_struct) assert(listener_opts = test_struct.listener_opts) assert_equal expect, listener_opts[listener] end @@ -124,9 +121,7 @@ class TestConfigurator < Test::Unit::TestCase expect = { :delay => 0.5 } listener = "127.0.0.1:12345" tmp.syswrite("listen '#{listener}', #{expect.inspect}\n") - assert_nothing_raised do - Unicorn::Configurator.new(:config_file => tmp.path) - end + Unicorn::Configurator.new(:config_file => tmp.path) end def test_listen_option_int_delay @@ -134,9 +129,7 @@ class TestConfigurator < Test::Unit::TestCase expect = { :delay => 5 } listener = "127.0.0.1:12345" tmp.syswrite("listen '#{listener}', #{expect.inspect}\n") - assert_nothing_raised do - Unicorn::Configurator.new(:config_file => tmp.path) - end + Unicorn::Configurator.new(:config_file => tmp.path) end def test_after_fork_proc diff --git a/test/unit/test_http_parser.rb b/test/unit/test_http_parser.rb index 797a449..64146e7 100644 --- a/test/unit/test_http_parser.rb +++ b/test/unit/test_http_parser.rb @@ -689,10 +689,7 @@ class HttpParserTest < Test::Unit::TestCase parser = HttpParser.new req = parser.env s = "#{m} /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n" - ok = false - assert_nothing_raised do - ok = parser.headers(req, s) - end + ok = parser.headers(req, s) assert ok assert_equal '/forums/1/topics/2375?page=1', req['REQUEST_URI'] assert_equal 'posts-17408', req['FRAGMENT'] @@ -708,10 +705,7 @@ class HttpParserTest < Test::Unit::TestCase req = parser.env get = "GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n" parser.buf << get - ok = false - assert_nothing_raised do - ok = parser.parse - end + ok = parser.parse assert ok assert_equal '/forums/1/topics/2375?page=1', req['REQUEST_URI'] assert_equal 'posts-17408', req['FRAGMENT'] diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index a5ee053..93c44bb 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -34,7 +34,7 @@ class HttpParserNgTest < Test::Unit::TestCase def test_connection_TE @parser.buf << "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: TE\r\n" @parser.buf << "TE: trailers\r\n\r\n" - assert_nothing_raised { @parser.parse } + @parser.parse assert @parser.keepalive? assert @parser.next? end @@ -94,10 +94,8 @@ class HttpParserNgTest < Test::Unit::TestCase def test_default_keepalive_is_off assert ! @parser.keepalive? assert ! @parser.next? - assert_nothing_raised do - @parser.buf << "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" - @parser.parse - end + @parser.buf << "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" + @parser.parse assert @parser.keepalive? @parser.clear assert ! @parser.keepalive? @@ -419,7 +417,7 @@ class HttpParserNgTest < Test::Unit::TestCase req = @parser.env assert_equal req, @parser.parse assert_nil @parser.content_length - assert_nothing_raised { @parser.filter_body('', str) } + @parser.filter_body('', str) assert ! @parser.keepalive? end @@ -427,7 +425,7 @@ class HttpParserNgTest < Test::Unit::TestCase n = HttpParser::LENGTH_MAX @parser.buf << "PUT / HTTP/1.1\r\nContent-Length: #{n}\r\n\r\n" req = @parser.env - assert_nothing_raised { @parser.headers(req, @parser.buf) } + @parser.headers(req, @parser.buf) assert_equal n, req['CONTENT_LENGTH'].to_i assert ! @parser.keepalive? end diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb index 4943dc0..a57cbcd 100644 --- a/test/unit/test_request.rb +++ b/test/unit/test_request.rb @@ -30,47 +30,43 @@ class RequestTest < Test::Unit::TestCase def test_options client = MockRequest.new("OPTIONS * HTTP/1.1\r\n" \ "Host: foo\r\n\r\n") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal '', env['REQUEST_PATH'] assert_equal '', env['PATH_INFO'] assert_equal '*', env['REQUEST_URI'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_absolute_uri_with_query client = MockRequest.new("GET http://e:3/x?y=z HTTP/1.1\r\n" \ "Host: foo\r\n\r\n") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal '/x', env['REQUEST_PATH'] assert_equal '/x', env['PATH_INFO'] assert_equal 'y=z', env['QUERY_STRING'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_absolute_uri_with_fragment client = MockRequest.new("GET http://e:3/x#frag HTTP/1.1\r\n" \ "Host: foo\r\n\r\n") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal '/x', env['REQUEST_PATH'] assert_equal '/x', env['PATH_INFO'] assert_equal '', env['QUERY_STRING'] assert_equal 'frag', env['FRAGMENT'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_absolute_uri_with_query_and_fragment client = MockRequest.new("GET http://e:3/x?a=b#frag HTTP/1.1\r\n" \ "Host: foo\r\n\r\n") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal '/x', env['REQUEST_PATH'] assert_equal '/x', env['PATH_INFO'] assert_equal 'a=b', env['QUERY_STRING'] assert_equal 'frag', env['FRAGMENT'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_absolute_uri_unsupported_schemes @@ -82,48 +78,43 @@ class RequestTest < Test::Unit::TestCase end def test_x_forwarded_proto_https - res = env = nil client = MockRequest.new("GET / HTTP/1.1\r\n" \ "X-Forwarded-Proto: https\r\n" \ "Host: foo\r\n\r\n") - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal "https", env['rack.url_scheme'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_x_forwarded_proto_http - res = env = nil client = MockRequest.new("GET / HTTP/1.1\r\n" \ "X-Forwarded-Proto: http\r\n" \ "Host: foo\r\n\r\n") - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal "http", env['rack.url_scheme'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_x_forwarded_proto_invalid - res = env = nil client = MockRequest.new("GET / HTTP/1.1\r\n" \ "X-Forwarded-Proto: ftp\r\n" \ "Host: foo\r\n\r\n") - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal "http", env['rack.url_scheme'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_rack_lint_get client = MockRequest.new("GET / HTTP/1.1\r\nHost: foo\r\n\r\n") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal "http", env['rack.url_scheme'] assert_equal '127.0.0.1', env['REMOTE_ADDR'] - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_no_content_stringio client = MockRequest.new("GET / HTTP/1.1\r\nHost: foo\r\n\r\n") - env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal StringIO, env['rack.input'].class end @@ -131,8 +122,7 @@ class RequestTest < Test::Unit::TestCase client = MockRequest.new("PUT / HTTP/1.1\r\n" \ "Content-Length: 0\r\n" \ "Host: foo\r\n\r\n") - env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal StringIO, env['rack.input'].class end @@ -140,8 +130,7 @@ class RequestTest < Test::Unit::TestCase client = MockRequest.new("PUT / HTTP/1.1\r\n" \ "Content-Length: 1\r\n" \ "Host: foo\r\n\r\n") - env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert_equal Unicorn::TeeInput, env['rack.input'].class end @@ -152,10 +141,9 @@ class RequestTest < Test::Unit::TestCase "Content-Length: 5\r\n" \ "\r\n" \ "abcde") - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert ! env.include?(:http_body) - assert_nothing_raised { res = @lint.call(env) } + res = @lint.call(env) end def test_rack_lint_big_put @@ -179,8 +167,7 @@ class RequestTest < Test::Unit::TestCase "\r\n") count.times { assert_equal bs, client.syswrite(buf) } assert_equal 0, client.sysseek(0) - res = env = nil - assert_nothing_raised { env = @request.read(client) } + env = @request.read(client) assert ! env.include?(:http_body) assert_equal length, env['rack.input'].size count.times { @@ -189,9 +176,7 @@ class RequestTest < Test::Unit::TestCase assert_equal buf, tmp } assert_nil env['rack.input'].read(bs) - assert_nothing_raised { env['rack.input'].rewind } - assert_nothing_raised { res = @lint.call(env) } + env['rack.input'].rewind + res = @lint.call(env) end - end - diff --git a/test/unit/test_server.rb b/test/unit/test_server.rb index 4d06dd3..a821790 100644 --- a/test/unit/test_server.rb +++ b/test/unit/test_server.rb @@ -92,14 +92,10 @@ class WebServerTest < Test::Unit::TestCase @server = HttpServer.new(app, :listeners => [ "127.0.0.1:#@port"] ) @server.start end - sock = nil - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - end - + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") assert_match %r{\AHTTP/1.[01] 500\b}, sock.sysread(4096) - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_simple_server @@ -108,56 +104,48 @@ class WebServerTest < Test::Unit::TestCase end def test_client_shutdown_writes - sock = nil - buf = nil bs = 15609315 * rand - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("PUT /hello HTTP/1.1\r\n") - sock.syswrite("Host: example.com\r\n") - sock.syswrite("Transfer-Encoding: chunked\r\n") - sock.syswrite("Trailer: X-Foo\r\n") - sock.syswrite("\r\n") - sock.syswrite("%x\r\n" % [ bs ]) - sock.syswrite("F" * bs) - sock.syswrite("\r\n0\r\nX-") - "Foo: bar\r\n\r\n".each_byte do |x| - sock.syswrite x.chr - sleep 0.05 - end - # we wrote the entire request before shutting down, server should - # continue to process our request and never hit EOFError on our sock - sock.shutdown(Socket::SHUT_WR) - buf = sock.read + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("PUT /hello HTTP/1.1\r\n") + sock.syswrite("Host: example.com\r\n") + sock.syswrite("Transfer-Encoding: chunked\r\n") + sock.syswrite("Trailer: X-Foo\r\n") + sock.syswrite("\r\n") + sock.syswrite("%x\r\n" % [ bs ]) + sock.syswrite("F" * bs) + sock.syswrite("\r\n0\r\nX-") + "Foo: bar\r\n\r\n".each_byte do |x| + sock.syswrite x.chr + sleep 0.05 end + # we wrote the entire request before shutting down, server should + # continue to process our request and never hit EOFError on our sock + sock.shutdown(Socket::SHUT_WR) + buf = sock.read assert_equal 'hello!\n', buf.split(/\r\n\r\n/).last next_client = Net::HTTP.get(URI.parse("http://127.0.0.1:#@port/")) assert_equal 'hello!\n', next_client lines = File.readlines("test_stderr.#$$.log") assert lines.grep(/^Unicorn::ClientShutdown: /).empty? - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_client_shutdown_write_truncates - sock = nil - buf = nil bs = 15609315 * rand - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("PUT /hello HTTP/1.1\r\n") - sock.syswrite("Host: example.com\r\n") - sock.syswrite("Transfer-Encoding: chunked\r\n") - sock.syswrite("Trailer: X-Foo\r\n") - sock.syswrite("\r\n") - sock.syswrite("%x\r\n" % [ bs ]) - sock.syswrite("F" * (bs / 2.0)) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("PUT /hello HTTP/1.1\r\n") + sock.syswrite("Host: example.com\r\n") + sock.syswrite("Transfer-Encoding: chunked\r\n") + sock.syswrite("Trailer: X-Foo\r\n") + sock.syswrite("\r\n") + sock.syswrite("%x\r\n" % [ bs ]) + sock.syswrite("F" * (bs / 2.0)) - # shutdown prematurely, this will force the server to abort - # processing on us even during app dispatch - sock.shutdown(Socket::SHUT_WR) - IO.select([sock], nil, nil, 60) or raise "Timed out" - buf = sock.read - end + # shutdown prematurely, this will force the server to abort + # processing on us even during app dispatch + sock.shutdown(Socket::SHUT_WR) + IO.select([sock], nil, nil, 60) or raise "Timed out" + buf = sock.read assert_equal "", buf next_client = Net::HTTP.get(URI.parse("http://127.0.0.1:#@port/")) assert_equal 'hello!\n', next_client @@ -165,27 +153,24 @@ class WebServerTest < Test::Unit::TestCase lines = lines.grep(/^Unicorn::ClientShutdown: bytes_read=\d+/) assert_equal 1, lines.size assert_match %r{\AUnicorn::ClientShutdown: bytes_read=\d+ true$}, lines[0] - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_client_malformed_body - sock = nil bs = 15653984 - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("PUT /hello HTTP/1.1\r\n") - sock.syswrite("Host: example.com\r\n") - sock.syswrite("Transfer-Encoding: chunked\r\n") - sock.syswrite("Trailer: X-Foo\r\n") - sock.syswrite("\r\n") - sock.syswrite("%x\r\n" % [ bs ]) - sock.syswrite("F" * bs) - end + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("PUT /hello HTTP/1.1\r\n") + sock.syswrite("Host: example.com\r\n") + sock.syswrite("Transfer-Encoding: chunked\r\n") + sock.syswrite("Trailer: X-Foo\r\n") + sock.syswrite("\r\n") + sock.syswrite("%x\r\n" % [ bs ]) + sock.syswrite("F" * bs) begin File.open("/dev/urandom", "rb") { |fp| sock.syswrite(fp.sysread(16384)) } rescue end - assert_nothing_raised { sock.close } + assert_nil sock.close next_client = Net::HTTP.get(URI.parse("http://127.0.0.1:#@port/")) assert_equal 'hello!\n', next_client lines = File.readlines("test_stderr.#$$.log") @@ -240,23 +225,17 @@ class WebServerTest < Test::Unit::TestCase end def test_bad_client_400 - sock = nil - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\nHost: foo\rbar\r\n\r\n") - end + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\nHost: foo\rbar\r\n\r\n") assert_match %r{\AHTTP/1.[01] 400\b}, sock.sysread(4096) - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_http_0_9 - sock = nil - assert_nothing_raised do - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET /hello\r\n") - end + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET /hello\r\n") assert_match 'hello!\n', sock.sysread(4096) - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_header_is_too_long diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb index 0adf153..84d6a4b 100644 --- a/test/unit/test_signals.rb +++ b/test/unit/test_signals.rb @@ -51,22 +51,19 @@ class SignalsTest < Test::Unit::TestCase opts = @server_opts.merge(:timeout => 3) redirect_test_io { HttpServer.new(app, opts).start.join } } - child = sock = buf = t0 = nil - assert_nothing_raised do - wait_workers_ready("test_stderr.#{pid}.log", 1) - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - buf = sock.readpartial(4096) - sock.close - buf =~ /\bX-Pid: (\d+)\b/ or raise Exception - child = $1.to_i - wait_master_ready("test_stderr.#{pid}.log") - wait_workers_ready("test_stderr.#{pid}.log", 1) - Process.kill(:KILL, pid) - Process.waitpid(pid) - File.unlink("test_stderr.#{pid}.log", "test_stdout.#{pid}.log") - t0 = Time.now - end + wait_workers_ready("test_stderr.#{pid}.log", 1) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + buf = sock.readpartial(4096) + assert_nil sock.close + buf =~ /\bX-Pid: (\d+)\b/ or raise Exception + child = $1.to_i + wait_master_ready("test_stderr.#{pid}.log") + wait_workers_ready("test_stderr.#{pid}.log", 1) + Process.kill(:KILL, pid) + Process.waitpid(pid) + File.unlink("test_stderr.#{pid}.log", "test_stdout.#{pid}.log") + t0 = Time.now assert child assert t0 assert_raises(Errno::ESRCH) { loop { Process.kill(0, child); sleep 0.2 } } @@ -80,17 +77,14 @@ class SignalsTest < Test::Unit::TestCase app = lambda { |env| wr.syswrite('.'); sleep; [ 200, {}, [] ] } redirect_test_io { HttpServer.new(app, @server_opts).start.join } } - sock = buf = nil wr.close - assert_nothing_raised do - wait_workers_ready("test_stderr.#{pid}.log", 1) - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - buf = rd.readpartial(1) - wait_master_ready("test_stderr.#{pid}.log") - Process.kill(:INT, pid) - Process.waitpid(pid) - end + wait_workers_ready("test_stderr.#{pid}.log", 1) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + buf = rd.readpartial(1) + wait_master_ready("test_stderr.#{pid}.log") + Process.kill(:INT, pid) + Process.waitpid(pid) assert_equal '.', buf buf = nil assert_raises(EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL, @@ -98,7 +92,6 @@ class SignalsTest < Test::Unit::TestCase buf = sock.sysread(4096) end assert_nil buf - ensure end def test_timeout_slow_response @@ -108,12 +101,9 @@ class SignalsTest < Test::Unit::TestCase redirect_test_io { HttpServer.new(app, opts).start.join } } t0 = Time.now - sock = nil - assert_nothing_raised do - wait_workers_ready("test_stderr.#{pid}.log", 1) - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - end + wait_workers_ready("test_stderr.#{pid}.log", 1) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") buf = nil assert_raises(EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL, @@ -134,19 +124,14 @@ class SignalsTest < Test::Unit::TestCase Dd.new(@bs, @count) ] } redirect_test_io { @server = HttpServer.new(app, @server_opts).start } - sock = nil - assert_nothing_raised do - wait_workers_ready("test_stderr.#{$$}.log", 1) - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - end + wait_workers_ready("test_stderr.#{$$}.log", 1) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") buf = '' header_len = pid = nil - assert_nothing_raised do - buf = sock.sysread(16384, buf) - pid = buf[/\r\nX-Pid: (\d+)\r\n/, 1].to_i - header_len = buf[/\A(.+?\r\n\r\n)/m, 1].size - end + buf = sock.sysread(16384, buf) + pid = buf[/\r\nX-Pid: (\d+)\r\n/, 1].to_i + header_len = buf[/\A(.+?\r\n\r\n)/m, 1].size assert pid > 0, "pid not positive: #{pid.inspect}" read = buf.size size_before = @tmp.stat.size @@ -166,7 +151,7 @@ class SignalsTest < Test::Unit::TestCase got = read - header_len expect = @bs * @count assert_equal(expect, got, "expect=#{expect} got=#{got}") - assert_nothing_raised { sock.close } + assert_nil sock.close end def test_request_read @@ -176,15 +161,12 @@ class SignalsTest < Test::Unit::TestCase [ 200, {'Content-Type'=>'text/plain', 'X-Pid'=>Process.pid.to_s}, [] ] } redirect_test_io { @server = HttpServer.new(app, @server_opts).start } - pid = nil - - assert_nothing_raised do - wait_workers_ready("test_stderr.#{$$}.log", 1) - sock = TCPSocket.new('127.0.0.1', @port) - sock.syswrite("GET / HTTP/1.0\r\n\r\n") - pid = sock.sysread(4096)[/\r\nX-Pid: (\d+)\r\n/, 1].to_i - sock.close - end + + wait_workers_ready("test_stderr.#{$$}.log", 1) + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + pid = sock.sysread(4096)[/\r\nX-Pid: (\d+)\r\n/, 1].to_i + assert_nil sock.close assert pid > 0, "pid not positive: #{pid.inspect}" sock = TCPSocket.new('127.0.0.1', @port) @@ -201,7 +183,6 @@ class SignalsTest < Test::Unit::TestCase # can't check for == since pending signals get merged assert size_before < @tmp.stat.size assert_equal pid, sock.sysread(4096)[/\r\nX-Pid: (\d+)\r\n/, 1].to_i - sock.close + assert_nil sock.close end - end diff --git a/test/unit/test_socket_helper.rb b/test/unit/test_socket_helper.rb index f099391..a38082c 100644 --- a/test/unit/test_socket_helper.rb +++ b/test/unit/test_socket_helper.rb @@ -37,16 +37,13 @@ class TestSocketHelper < Test::Unit::TestCase [ { :backlog => 5 }, { :sndbuf => 4096 }, { :rcvbuf => 4096 }, { :backlog => 16, :rcvbuf => 4096, :sndbuf => 4096 } ].each do |opts| - assert_nothing_raised do - tcp_listener = bind_listen(tcp_listener_name, opts) - assert TCPServer === tcp_listener - tcp_listener.close - unix_listener = bind_listen(unix_listener_name, opts) - assert UNIXServer === unix_listener - unix_listener.close - end + tcp_listener = bind_listen(tcp_listener_name, opts) + assert TCPServer === tcp_listener + tcp_listener.close + unix_listener = bind_listen(unix_listener_name, opts) + assert UNIXServer === unix_listener + unix_listener.close end - #system('cat', @log_tmp.path) end def test_bind_listen_unix @@ -106,10 +103,10 @@ class TestSocketHelper < Test::Unit::TestCase assert_raises(Errno::EADDRINUSE) do new_listener = bind_listen(@unix_listener_path) end - assert_nothing_raised do - File.unlink(@unix_listener_path) - new_listener = bind_listen(@unix_listener_path) - end + + File.unlink(@unix_listener_path) + new_listener = bind_listen(@unix_listener_path) + assert UNIXServer === new_listener assert new_listener.fileno != @unix_listener.fileno assert_equal sock_name(new_listener), sock_name(@unix_listener) @@ -127,10 +124,8 @@ class TestSocketHelper < Test::Unit::TestCase end def test_server_cast - assert_nothing_raised do - test_bind_listen_unix - test_bind_listen_tcp - end + test_bind_listen_unix + test_bind_listen_tcp unix_listener_socket = Socket.for_fd(@unix_listener.fileno) assert Socket === unix_listener_socket @unix_server = server_cast(unix_listener_socket) diff --git a/test/unit/test_stream_input.rb b/test/unit/test_stream_input.rb index f59157a..1a07ec3 100644 --- a/test/unit/test_stream_input.rb +++ b/test/unit/test_stream_input.rb @@ -85,8 +85,7 @@ class TestStreamInput < Test::Unit::TestCase assert_equal '....', si.read(4), "nr=#{x}" } assert_nil si.read(1) - status = nil - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end @@ -101,13 +100,13 @@ class TestStreamInput < Test::Unit::TestCase @wr.close } @wr.close - assert_nothing_raised { line = si.gets } + line = si.gets assert_equal(4096 * 4 * 3 + 5 + $/.size, line.size) assert_equal("hello" << ("ffff" * 4096 * 3) << "#$/", line) - assert_nothing_raised { line = si.gets } + line = si.gets assert_equal "foo#$/", line assert_nil si.gets - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb index 96eb268..0c2c941 100644 --- a/test/unit/test_tee_input.rb +++ b/test/unit/test_tee_input.rb @@ -40,13 +40,13 @@ class TestTeeInput < Test::Unit::TestCase @wr.close } @wr.close - assert_nothing_raised { line = ti.gets } + line = ti.gets assert_equal(4096 * 4 * 3 + 5 + $/.size, line.size) assert_equal("hello" << ("ffff" * 4096 * 3) << "#$/", line) - assert_nothing_raised { line = ti.gets } + line = ti.gets assert_equal "foo#$/", line assert_nil ti.gets - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end @@ -60,12 +60,12 @@ class TestTeeInput < Test::Unit::TestCase @wr.close } @wr.close - assert_nothing_raised { line = ti.gets } + line = ti.gets assert_equal("hello#$/", line) - assert_nothing_raised { line = ti.gets } + line = ti.gets assert_equal "foo", line assert_nil ti.gets - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end @@ -146,8 +146,7 @@ class TestTeeInput < Test::Unit::TestCase assert_equal Unicorn::Const::MAX_BODY + 1, ti.size } assert_nil ti.read(1) - status = nil - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end @@ -174,15 +173,15 @@ class TestTeeInput < Test::Unit::TestCase assert @parser.body_eof? assert_equal 25, ti.len assert_equal 0, ti.tmp.pos - assert_nothing_raised { ti.rewind } + ti.rewind assert_equal 0, ti.tmp.pos assert_equal 'abcdeabcdeabcdeabcde', ti.read(20) assert_equal 20, ti.tmp.pos - assert_nothing_raised { ti.rewind } + ti.rewind assert_equal 0, ti.tmp.pos assert_kind_of File, ti.tmp status = nil - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end @@ -241,8 +240,7 @@ class TestTeeInput < Test::Unit::TestCase assert ! @parser.body_eof? assert_equal 25, ti.size assert_equal "World", @parser.env['HTTP_HELLO'] - status = nil - assert_nothing_raised { pid, status = Process.waitpid2(pid) } + pid, status = Process.waitpid2(pid) assert status.success? end diff --git a/test/unit/test_upload.rb b/test/unit/test_upload.rb index 7777e00..bcce4bc 100644 --- a/test/unit/test_upload.rb +++ b/test/unit/test_upload.rb @@ -163,7 +163,7 @@ class UploadTest < Test::Unit::TestCase assert_raise(Errno::ECONNRESET, Errno::EPIPE) do ::Unicorn::Const::CHUNK_SIZE.times { sock.syswrite(buf) } end - assert_nothing_raised { sock.gets } + sock.gets tmp.rewind assert_equal length, tmp.read.to_i end -- cgit v1.2.3-24-ge0c7