Skip to content

Commit

Permalink
Add hot restart integration test
Browse files Browse the repository at this point in the history
This test demonstrates that it's possible for clients to receive
unexpected ECONNRESET errors during hot restarts.

CI shows that the test fails on various platforms/rubies, such as JRuby
and TruffleRuby on Ubuntu as well as MRI on macOS. No failures for MRI
on Ubuntu or MRI on Windows.
  • Loading branch information
cjlarose committed Oct 1, 2020
1 parent a73587f commit c203014
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/test_integration_single.rb
Expand Up @@ -10,6 +10,59 @@ def test_usr2_restart
assert_equal "Hello World", new_reply
end

def test_hot_restart_does_not_drop_connections
skip_unless_signal_exist? :USR2

replies = Hash.new 0
num_requests = 500
refused = thread_run_refused unix: false
message = 'A' * 2**14

cli_server "-q test/rackup/hello.ru"

client_thread = Thread.new do
num_requests.times do
begin
socket = TCPSocket.new(HOST, @tcp_port)
@ios_to_close << socket
socket << "POST / HTTP/1.1\r\nContent-Length: #{message.bytesize}\r\n\r\n#{message}"
true until socket.gets == "\r\n"
body = read_body(socket, 20)
if body == "Hello World"
replies[:success] += 1
else
replies[:unexpected_response] += 1
end
rescue Errno::ECONNRESET
# connection was accepted but then closed
# client would see an empty response
replies[:reset] += 1
rescue *refused
replies[:refused] += 1
end
end
end

run = true

restart_thread = Thread.new do
while run
Process.kill :USR2, @pid
wait_for_server_to_boot
sleep 1
end
end

client_thread.join
run = false
restart_thread.join

assert_equal 0, replies[:unexpected_response], "Unexpected response"
assert_equal 0, replies[:reset], "Expected no reset errors"
assert_equal 0, replies[:refused], "Expected no refused connections"
assert_equal num_requests, replies[:success]
end

# It does not share environments between multiple generations, which would break Dotenv
def test_usr2_restart_restores_environment
# jruby has a bug where setting `nil` into the ENV or `delete` do not change the
Expand Down

0 comments on commit c203014

Please sign in to comment.