From fcb99b91cccc0d790208213ea88ae6c698db7633 Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Mon, 11 Nov 2019 18:56:45 -0500 Subject: [PATCH] Close connection in web server tests (#2072) [skip changelog] Closes #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 --- test/test_web_server.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test_web_server.rb b/test/test_web_server.rb index c8073b0681..5e9daa7fa0 100644 --- a/test/test_web_server.rb +++ b/test/test_web_server.rb @@ -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 @@ -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