From 6d7e11482a484b50215701993408057b80c82bbe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 Nov 2009 12:09:14 -0800 Subject: test_server: ensure stderr is written to before reading This works around a race condition caused by the server closing the connection before writing out to stderr in the ensure block. So to ensure we've waited on the server to write to the log file, just send another HTTP request since we know our test server only processes requests serially. --- test/unit/test_server.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/unit/test_server.rb b/test/unit/test_server.rb index a7f6a35..7f0c443 100644 --- a/test/unit/test_server.rb +++ b/test/unit/test_server.rb @@ -128,6 +128,8 @@ class WebServerTest < Test::Unit::TestCase buf = sock.read end 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 } @@ -154,6 +156,8 @@ class WebServerTest < Test::Unit::TestCase buf = sock.read end assert_equal "", buf + 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") lines = lines.grep(/^Unicorn::ClientShutdown: bytes_read=\d+/) assert_equal 1, lines.size -- cgit v1.2.3-24-ge0c7