Moved acceptance tests into tests/acceptance

This commit is contained in:
Alex Young
2012-07-03 10:59:31 +01:00
parent c0c9c6f076
commit 988b2ec014
20 changed files with 3 additions and 5 deletions

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
# Connects to the destination server, then immediately disconnects,
# simulating a source crash.
#
# It then connects again, to check that the destination is still
# listening.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
addr, port = *ARGV
connect( 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
exit 0

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
# Connect, read the hello, then immediately disconnect. This
# simulates a sender which dislikes something in the hello message - a
# wrong size, for instance.
# After the disconnect, we reconnect to be sure that the destination
# is still alive.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
addr, port = *ARGV
client_sock = connect( addr, port, "Timed out connecting." )
read_hello( client_sock )
client_sock.close
sleep(0.2)
connect( addr, port, "Timed out reconnecting." )
exit(0)

View File

@@ -0,0 +1,19 @@
#!/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.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
addr, port = *ARGV
# client_sock1 is a connection the destination is expecting.
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
# And this is just a tidy-up.
client_sock2.close

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
# encoding: utf-8
# We connect from a local address which should be blocked, sleep for a
# bit, then try to read from the socket. We should get an instant EOF
# as we've been cut off by the destination.
require 'timeout'
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
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
exit(0)

View File

@@ -0,0 +1,39 @@
#!/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::FakeSource
client_sock = connect( addr, port, "Timed out connecting" )
read_hello( client_sock )
# 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_sock.close
new_sock = nil
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 1 )
new_sock = connect( addr, port, "Timed out reconnecting." )
read_hello( new_sock )
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
_,status = Process.waitpid2( kidpid )
exit status.exitstatus

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Connect, read the hello then make a write request with an impossible
# (from,len) pair. We expect an error response, and not to be
# disconnected.
require 'flexnbd/fake_source'
include FlexNBD::FakeSource
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 )
fail "Not an error" if response[:error] == 0
fail "Wrong handle" unless "myhandle" == response[:handle]
client_sock.close
exit(0)