Test that timing out a write causes a disconnect and a reconnect
This commit is contained in:
27
tests/fakes/dest/hang_after_write.rb
Executable file
27
tests/fakes/dest/hang_after_write.rb
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env ruby
|
||||
# encoding: utf-8
|
||||
|
||||
# Open a socket, say hello, receive a write, then sleep for > 6
|
||||
# seconds. This should tell the source that the write has gone MIA,
|
||||
# and we expect a reconnect.
|
||||
|
||||
require 'flexnbd/fake_dest'
|
||||
include FlexNBD::FakeDest
|
||||
|
||||
sock = serve( *ARGV )
|
||||
client_sock1 = accept( sock )
|
||||
write_hello( client_sock1 )
|
||||
read_request( client_sock1 )
|
||||
|
||||
t = Thread.start do
|
||||
client_sock2 = accept( sock, "Timed out waiting for a reconnection",
|
||||
FlexNBD::MS_REQUEST_LIMIT_SECS + 1 )
|
||||
client_sock2.close
|
||||
end
|
||||
|
||||
sleep( FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
|
||||
client_sock1.close
|
||||
|
||||
t.join
|
||||
|
||||
exit(0)
|
@@ -13,7 +13,7 @@ module FlexNBD
|
||||
end
|
||||
|
||||
|
||||
def accept( sock, err_msg, timeout=2 )
|
||||
def accept( sock, err_msg = "Timed out waiting for a connection", timeout=2 )
|
||||
client_sock = nil
|
||||
|
||||
begin
|
||||
@@ -47,5 +47,11 @@ module FlexNBD
|
||||
client_sock.write( "\x00" * 128 )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def read_request( client_sock )
|
||||
client_sock.read(28)
|
||||
end
|
||||
|
||||
|
||||
end # module FakeDest
|
||||
end # module FlexNBD
|
||||
|
@@ -274,6 +274,14 @@ class NBDConnectSourceFailureScenarios < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
def test_write_times_out_causes_retry
|
||||
@env.run_fake( "dest/hang_after_write", @env.ip, @env.port2 )
|
||||
stdout, stderr = @env.mirror12_unchecked
|
||||
|
||||
assert @env.fake_reports_success, "Fake failed."
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user