Files
flexnbd-c/tests/acceptance/fakes/source/hang_after_hello.rb

40 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2012-06-22 10:05:41 +01:00
#!/usr/bin/env ruby
# Simulate the hello message going astray, or the source hanging after
# receiving it.
#
# We then connect again, to confirm that the destination is still
# listening for an incoming migration.
addr, port = *ARGV
require "flexnbd/fake_source"
include FlexNBD
2012-06-22 10:05:41 +01:00
client = FakeSource.new( addr, port, "Timed out connecting" )
client.read_hello
2012-06-22 10:05:41 +01:00
# Now we do two things:
# - In the parent process, we sleep for CLIENT_MAX_WAIT_SECS+5, which
# will make the destination give up and close the connection.
# - In the child process, we sleep for CLIENT_MAX_WAIT_SECS+1, which
# should be able to reconnect despite the parent process not having
# closed its end yet.
kidpid = fork do
client.close
new_client = nil
2012-06-22 10:05:41 +01:00
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 1 )
new_client = FakeSource.new( addr, port, "Timed out reconnecting." )
new_client.read_hello
2012-06-22 10:05:41 +01:00
exit 0
end
# Sleep for longer than the child, to give the flexnbd process a bit
# of slop
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 3 )
client.close
2012-06-22 10:05:41 +01:00
_,status = Process.waitpid2( kidpid )
exit status.exitstatus