Factor common code out of the test fake sources
* * * More fake source refacoring
This commit is contained in:
@@ -7,43 +7,16 @@
|
||||
# After the disconnect, we reconnect to be sure that the destination
|
||||
# is still alive.
|
||||
|
||||
|
||||
require 'socket'
|
||||
require "timeout"
|
||||
require 'flexnbd/constants'
|
||||
require 'flexnbd/fake_source'
|
||||
include FlexNBD::FakeSource
|
||||
|
||||
addr, port = *ARGV
|
||||
|
||||
client_sock = nil
|
||||
begin
|
||||
Timeout.timeout(2) do
|
||||
client_sock = TCPSocket.open( addr, port )
|
||||
end
|
||||
rescue Timeout::Error
|
||||
$stderr.puts "Timed out connecting."
|
||||
exit 1
|
||||
end
|
||||
|
||||
begin
|
||||
Timeout.timeout( FlexNBD::MS_HELLO_TIME_SECS ) do
|
||||
fail "No hello." unless (hello = client_sock.read( 152 )) &&
|
||||
hello.length==152
|
||||
end
|
||||
rescue Timeout::Error
|
||||
$stderr.puts "Timed out waiting for hello."
|
||||
exit 1
|
||||
end
|
||||
|
||||
client_sock = connect( addr, port, "Timed out connecting." )
|
||||
read_hello( client_sock )
|
||||
client_sock.close
|
||||
|
||||
sleep(0.2)
|
||||
begin
|
||||
Timeout.timeout(2) do
|
||||
client_sock = TCPSocket.open( addr, port )
|
||||
end
|
||||
rescue Timeout::Error
|
||||
$stderr.puts "Timed out reconnecting."
|
||||
exit 1
|
||||
end
|
||||
connect( addr, port, "Timed out reconnecting." )
|
||||
|
||||
exit(0)
|
||||
|
Reference in New Issue
Block a user