Skip to content

Commit

Permalink
Close connection in web server tests
Browse files Browse the repository at this point in the history
[skip changelog]

Closes puma#2049

Before this commit, `test_trickle_attack` and
`test_file_streamed_request` were each taking an extra 20 seconds to run.

Without the `Connection: close` header, the [connection was kept
alive][keep alive] until it timed out after the
[`PERSISTENT_TIMEOUT`][PERSISTENT_TIMEOUT] duration of 20 seconds.

[keep alive]: https://github.com/puma/puma/blob/3835ac74dec5511d637cbc4ebc140c3b8632b447/lib/puma/server.rb#L706-L708
[PERSISTENT_TIMEOUT]: https://github.com/puma/puma/blob/3835ac74dec5511d637cbc4ebc140c3b8632b447/lib/puma/const.rb#L109-L111
  • Loading branch information
composerinteralia committed Nov 11, 2019
1 parent 3835ac7 commit 86d6405
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions test/test_web_server.rb
Expand Up @@ -19,7 +19,7 @@ def call(env)
class WebServerTest < Minitest::Test
parallelize_me!

VALID_REQUEST = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
VALID_REQUEST = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n"

def setup
@tester = TestHandler.new
Expand Down Expand Up @@ -63,10 +63,9 @@ def test_header_is_too_long
end
end

# TODO: Why does this test take exactly 20 seconds?
def test_file_streamed_request
body = "a" * (Puma::Const::MAX_BODY * 2)
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\nConnection: close\r\n\r\n" + body
socket = do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
assert_match "hello", socket.read
socket.close
Expand Down

0 comments on commit 86d6405

Please sign in to comment.