Factor common code out of the test fake sources

* * *
More fake source refacoring
This commit is contained in:
Alex Young
2012-06-27 17:28:24 +01:00
parent 137a764cc7
commit 192471ee82
5 changed files with 66 additions and 108 deletions

View File

@@ -1,34 +1,17 @@
#!/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.
# destination. This will trigger the destination's thread clearer.
require 'socket'
require 'timeout'
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
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
client_sock1 = connect( addr, port, "Timed out connecting" )
sleep(0.25)
client_sock2 = connect( addr, port, "Timed out connecting a second time" )
# This is the expected source crashing after connect
client_sock1.close