mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
test_web_server.rb - fix intermittent errors (#1898)
Intermittent errors may be related to OS buffering, etc. Seems to fix issue.
This commit is contained in:
parent
f372d329ce
commit
770e76cada
1 changed files with 21 additions and 3 deletions
|
@ -39,23 +39,25 @@ class WebServerTest < Minitest::Test
|
||||||
def test_trickle_attack
|
def test_trickle_attack
|
||||||
socket = do_test(VALID_REQUEST, 3)
|
socket = do_test(VALID_REQUEST, 3)
|
||||||
assert_match "hello", socket.read
|
assert_match "hello", socket.read
|
||||||
|
socket.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_close_client
|
def test_close_client
|
||||||
assert_raises IOError do
|
assert_raises IOError do
|
||||||
do_test(VALID_REQUEST, 10, 20)
|
do_test_raise(VALID_REQUEST, 10, 20)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_bad_client
|
def test_bad_client
|
||||||
socket = do_test("GET /test HTTP/BAD", 3)
|
socket = do_test("GET /test HTTP/BAD", 3)
|
||||||
assert_match "Bad Request", socket.read
|
assert_match "Bad Request", socket.read
|
||||||
|
socket.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header_is_too_long
|
def test_header_is_too_long
|
||||||
long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
|
long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
|
||||||
assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
|
assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
|
||||||
do_test(long, long.length/2, 10)
|
do_test_raise(long, long.length/2, 10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,11 +67,25 @@ class WebServerTest < Minitest::Test
|
||||||
long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
|
long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
|
||||||
socket = do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
|
socket = do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
|
||||||
assert_match "hello", socket.read
|
assert_match "hello", socket.read
|
||||||
|
socket.close
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def do_test(string, chunk, close_after=nil)
|
def do_test(string, chunk)
|
||||||
|
# Do not use instance variables here, because it needs to be thread safe
|
||||||
|
socket = TCPSocket.new("127.0.0.1", @server.connected_port);
|
||||||
|
request = StringIO.new(string)
|
||||||
|
chunks_out = 0
|
||||||
|
|
||||||
|
while data = request.read(chunk)
|
||||||
|
chunks_out += socket.write(data)
|
||||||
|
socket.flush
|
||||||
|
end
|
||||||
|
socket
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_test_raise(string, chunk, close_after = nil)
|
||||||
# Do not use instance variables here, because it needs to be thread safe
|
# Do not use instance variables here, because it needs to be thread safe
|
||||||
socket = TCPSocket.new("127.0.0.1", @server.connected_port);
|
socket = TCPSocket.new("127.0.0.1", @server.connected_port);
|
||||||
request = StringIO.new(string)
|
request = StringIO.new(string)
|
||||||
|
@ -84,5 +100,7 @@ class WebServerTest < Minitest::Test
|
||||||
socket.write(" ") # Some platforms only raise the exception on attempted write
|
socket.write(" ") # Some platforms only raise the exception on attempted write
|
||||||
socket.flush
|
socket.flush
|
||||||
socket
|
socket
|
||||||
|
ensure
|
||||||
|
socket.close unless socket.closed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue