Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 5acf552
  • Loading branch information...
commit f4af812a28b03508c96853739aea53f7a6714abf 1 parent 4bd0dbd
Eric Wong authored
View
31 test/test_helper.rb
@@ -155,9 +155,8 @@ def retry_hit(uris = [])
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 @@ def wait_master_ready(master_log)
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)
View
21 test/unit/test_configurator.rb
@@ -9,7 +9,7 @@
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 @@ def test_config_non_existent
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 @@ def test_config_defaults_skip
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 @@ def test_listen_options
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 @@ def test_listen_option_float_delay
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 @@ def test_listen_option_int_delay
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
View
10 test/unit/test_http_parser.rb
@@ -689,10 +689,7 @@ def test_unknown_methods
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 @@ def test_fragment_in_uri
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']
View
12 test/unit/test_http_parser_ng.rb
@@ -34,7 +34,7 @@ def test_keepalive_requests_setting
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 @@ def test_fewer_keepalive_requests_with_next?
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 @@ def test_max_chunk
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 @@ def test_max_body
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
View
63 test/unit/test_request.rb
@@ -30,47 +30,43 @@ def setup
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 @@ def test_absolute_uri_unsupported_schemes
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 @@ def test_zero_content_stringio
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 @@ def test_real_content_not_stringio
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 @@ def test_rack_lint_put
"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 @@ def client.kgio_read!(*args)
"\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 @@ def client.kgio_read!(*args)
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
-
View
119 test/unit/test_server.rb
@@ -92,14 +92,10 @@ def test_broken_app
@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 @@ def test_simple_server
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 @@ def test_client_shutdown_write_truncates
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 @@ def test_logger_changed
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
View
93 test/unit/test_signals.rb
@@ -51,22 +51,19 @@ def test_worker_dies_on_dead_master
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 @@ def test_sleepy_kill
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 @@ def test_sleepy_kill
buf = sock.sysread(4096)
end
assert_nil buf
- ensure
end
def test_timeout_slow_response
@@ -108,12 +101,9 @@ def test_timeout_slow_response
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 @@ def test_response_write
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 @@ def test_response_write
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 @@ def test_request_read
[ 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 @@ def test_request_read
# 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
View
29 test/unit/test_socket_helper.rb
@@ -37,16 +37,13 @@ def test_bind_listen_options
[ { :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 @@ def test_bind_listen_unix_rebind
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 @@ def test_bind_listen_unix_rebind
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)
View
9 test/unit/test_stream_input.rb
@@ -85,8 +85,7 @@ def test_big_body_multi
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 @@ def test_gets_long
@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
View
24 test/unit/test_tee_input.rb
@@ -40,13 +40,13 @@ def test_gets_long
@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 @@ def test_gets_short
@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 @@ def test_big_body_multi
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 @@ def test_chunked
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 @@ def test_chunked_with_trailer
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
View
2  test/unit/test_upload.rb
@@ -163,7 +163,7 @@ def test_put_excessive_overwrite_closed
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
Please sign in to comment.
Something went wrong with that request. Please try again.