Add a test for a second client connecting during a mirror
This commit is contained in:
36
tests/fakes/source/connect_during_hello.rb
Executable file
36
tests/fakes/source/connect_during_hello.rb
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# Connect to the destination, then hang. Connect a second time to the
|
||||||
|
# destinatioin. This will trigger the destination's thread clearer.
|
||||||
|
|
||||||
|
require 'socket'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
|
addr, port = *ARGV
|
||||||
|
|
||||||
|
# client_sock1 is a connection the destination is expecting.
|
||||||
|
client_sock1 = nil
|
||||||
|
begin
|
||||||
|
Timeout.timeout(2) do
|
||||||
|
client_sock1 = TCPSocket.open( addr, port )
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
$stderr.puts "Timed out connecting."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
#client_sock2 is the interloper.
|
||||||
|
client_sock2 = nil
|
||||||
|
begin
|
||||||
|
Timeout.timeout(2) do
|
||||||
|
client_sock2 = TCPSocket.open( addr, port )
|
||||||
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
$stderr.puts "Timed out connecting a second time."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# This is the expected source crashing after connect
|
||||||
|
client_sock1.close
|
||||||
|
# And this is just a tidy-up.
|
||||||
|
client_sock2.close
|
@@ -313,7 +313,9 @@ class FlexNBD
|
|||||||
end
|
end
|
||||||
|
|
||||||
def kill
|
def kill
|
||||||
can_die(2)
|
# At this point, to a certain degree we don't care what the exit
|
||||||
|
# status is
|
||||||
|
can_die(1)
|
||||||
if @pid
|
if @pid
|
||||||
begin
|
begin
|
||||||
Process.kill("INT", @pid)
|
Process.kill("INT", @pid)
|
||||||
|
@@ -263,6 +263,8 @@ class NBDConnectSourceFailureScenarios < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert @env.fake_reports_success
|
assert @env.fake_reports_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -280,26 +282,28 @@ class NBDConnectDestFailureScenarios < Test::Unit::TestCase
|
|||||||
|
|
||||||
|
|
||||||
def test_hello_blocked_by_disconnect_causes_error_not_fatal
|
def test_hello_blocked_by_disconnect_causes_error_not_fatal
|
||||||
@env.nbd1.can_die(1)
|
|
||||||
run_fake( "source/close_after_connect" )
|
run_fake( "source/close_after_connect" )
|
||||||
assert_no_control
|
assert_no_control
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_hello_goes_astray_causes_timeout_error
|
def test_hello_goes_astray_causes_timeout_error
|
||||||
@env.nbd1.can_die(1)
|
|
||||||
run_fake( "source/hang_after_hello" )
|
run_fake( "source/hang_after_hello" )
|
||||||
assert_no_control
|
assert_no_control
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_disconnect_after_hello_causes_error_not_fatal
|
def test_disconnect_after_hello_causes_error_not_fatal
|
||||||
@env.nbd1.can_die(1)
|
|
||||||
run_fake( "source/close_after_hello" )
|
run_fake( "source/close_after_hello" )
|
||||||
assert_no_control
|
assert_no_control
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_double_connect_during_hello
|
||||||
|
run_fake( "source/connect_during_hello" )
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def run_fake( name )
|
def run_fake( name )
|
||||||
@env.run_fake( name, @env.ip, @env.port1 )
|
@env.run_fake( name, @env.ip, @env.port1 )
|
||||||
|
Reference in New Issue
Block a user