Refactor FakeSource from a module to a class

This commit is contained in:
Alex Young
2012-07-03 14:39:05 +01:00
parent ded4914c84
commit 64ebbe7688
7 changed files with 70 additions and 54 deletions

View File

@@ -7,18 +7,17 @@
# listening.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
include FlexNBD
addr, port = *ARGV
connect( addr, port, "Failed to connect" ).close
FakeSource.new( addr, port, "Failed to connect" ).close
# Sleep to be sure we don't try to connect too soon. That wouldn't
# be a problem for the destination, but it would prevent us from
# determining success or failure here in the case where we try to
# reconnect before the destination has tidied up after the first
# thread went away.
sleep(0.5)
connect( addr, port, "Failed to reconnect" ).close
FakeSource.new( addr, port, "Failed to reconnect" ).close
exit 0

View File

@@ -8,15 +8,17 @@
# is still alive.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
include FlexNBD
addr, port = *ARGV
client_sock = connect( addr, port, "Timed out connecting." )
read_hello( client_sock )
client_sock.close
client = FakeSource.new( addr, port, "Timed out connecting." )
client.read_hello
client.close
sleep(0.2)
connect( addr, port, "Timed out reconnecting." )
FakeSource.new( addr, port, "Timed out reconnecting." )
exit(0)

View File

@@ -1,19 +1,22 @@
#!/usr/bin/env ruby
# Connect to the destination, then hang. Connect a second time to the
# destination. This will trigger the destination's thread clearer.
# destination. This will trigger the destination's thread clearer. We
# can't really see any error state from here, we just try to trigger
# something the test runner can detect.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
include FlexNBD
addr, port = *ARGV
# client_sock1 is a connection the destination is expecting.
client_sock1 = connect( addr, port, "Timed out connecting" )
client1 = FakeSource.new( addr, port, "Timed out connecting" )
sleep(0.25)
client_sock2 = connect( addr, port, "Timed out connecting a second time" )
client2 = FakeSource.new( addr, port, "Timed out connecting a second time" )
# This is the expected source crashing after connect
client_sock1.close
client1.close
# And this is just a tidy-up.
client_sock2.close
client2.close
exit(0)

View File

@@ -7,16 +7,15 @@
require 'timeout'
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
include FlexNBD
addr, port = *ARGV
sock = connect( addr, port, "Timed out connecting", "127.0.0.6" )
sleep( 0.25 )
Timeout.timeout( 2 ) do
fail "Not disconnected" if sock.read(1)
end
sock.close
client = FakeSource.new( addr, port, "Timed out connecting", "127.0.0.6" )
sleep( 0.25 )
client.ensure_disconnected
client.close
exit(0)

View File

@@ -8,10 +8,10 @@
addr, port = *ARGV
require "flexnbd/fake_source"
include FlexNBD::FakeSource
include FlexNBD
client_sock = connect( addr, port, "Timed out connecting" )
read_hello( client_sock )
client = FakeSource.new( addr, port, "Timed out connecting" )
client.read_hello
# Now we do two things:
@@ -22,18 +22,18 @@ read_hello( client_sock )
# closed its end yet.
kidpid = fork do
client_sock.close
new_sock = nil
client.close
new_client = nil
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 1 )
new_sock = connect( addr, port, "Timed out reconnecting." )
read_hello( new_sock )
new_client = FakeSource.new( addr, port, "Timed out reconnecting." )
new_client.read_hello
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_sock.close
client.close
_,status = Process.waitpid2( kidpid )
exit status.exitstatus

View File

@@ -6,16 +6,17 @@
# disconnected.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
include FlexNBD
addr, port = *ARGV
client_sock = connect( addr, port, "Timed out connecting" )
read_hello( client_sock )
write_write_request( client_sock, 1 << 31, 1 << 31, "myhandle" )
response = read_response( client_sock )
client = FakeSource.new( addr, port, "Timed out connecting" )
client.read_hello
client.write_write_request( 1 << 31, 1 << 31, "myhandle" )
response = client.read_response
fail "Not an error" if response[:error] == 0
fail "Wrong handle" unless "myhandle" == response[:handle]
client_sock.close
client.close
exit(0)