Check that a mirror write returning an error will cause a reconnect and retry

This commit is contained in:
Alex Young
2012-07-02 15:04:45 +01:00
parent 99f8c24b01
commit ea4642a878
10 changed files with 192 additions and 88 deletions

View File

@@ -7,19 +7,16 @@
# user, we have to keep trying.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( *ARGV )
client = server.accept( "Timed out waiting for a connection" )
client.write_hello
client.close
new_client = server.accept( "Timed out waiting for a reconnection" )
new_client.close
sock = serve( addr, port )
client_sock = accept( sock, "Timed out waiting for a connection" )
write_hello( client_sock )
client_sock.close
new_sock = accept( sock, "Timed out waiting for a reconnection" )
new_sock.close
sock.close
server.close
exit 0

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
# encoding: utf-8
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept
client.write_hello
handle = client.read_request[:handle]
client.write_error( handle )
client2 = server.accept( "Timed out waiting for a reconnection" )
client.close
client2.close
server.close
exit(0)

View File

@@ -8,16 +8,14 @@
# right error message after the timeout time.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
include FlexNBD
addr, port = *ARGV
serve_sock = serve( addr, port )
client_sock = accept( serve_sock, "Client didn't make a connection" )
server = FakeDest.new( *ARGV )
client = server.accept( "Client didn't make a connection" )
# Sleep for one second past the timeout (a bit of slop in case ruby
# doesn't launch things quickly)
sleep(FlexNBD::MS_HELLO_TIME_SECS + 1)
client_sock.close if client_sock
serve_sock.close
client.close
server.close

View File

@@ -6,22 +6,23 @@
# write has gone MIA, and we expect a reconnect.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
include FlexNBD
sock = serve( *ARGV )
client_sock1 = accept( sock )
write_hello( client_sock1 )
read_request( client_sock1 )
server = FakeDest.new( *ARGV )
client1 = server.accept( server )
client1.write_hello
client1.read_request
t = Thread.start do
client_sock2 = accept( sock, "Timed out waiting for a reconnection",
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
client_sock2.close
client2.close
end
sleep( FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
client_sock1.close
client1.close
t.join
server.close
exit(0)

View File

@@ -4,21 +4,21 @@
# We expect the sender to disconnect and reconnect.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
include FlexNBD
sock = serve( *ARGV )
client_sock = accept( sock, "Timed out waiting for a connection" )
server = FakeDest.new( *ARGV )
client1 = server.accept
# Launch a second thread so that we can spot the reconnection attempt
# as soon as it happens, or alternatively die a flaming death on
# timeout.
t = Thread.new do
client_sock2 = accept( sock, "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client_sock2.close
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2.close
end
write_hello( client_sock, :magic => :wrong )
client1.write_hello( :magic => :wrong )
t.join

View File

@@ -5,19 +5,18 @@
# EOF on read.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
sock = serve( *ARGV )
client_sock = accept( sock, "Timed out waiting for a connection" )
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept
t = Thread.new do
client_sock2 = accept( sock, "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client_sock2.close
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2.close
end
write_hello( client_sock, :size => :wrong )
client.write_hello( :size => :wrong )
t.join

View File

@@ -3,11 +3,11 @@
# Accept a connection, then immediately close it. This simulates an ACL rejection.
require 'flexnbd/fake_dest'
include FlexNBD::FakeDest
include FlexNBD
serve_sock = serve( *ARGV )
accept( serve_sock, "Timed out waiting for a connection" ).close
server = FakeDest.new( *ARGV )
server.accept.close
serve_sock.close
server.close
exit(0)