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,22 @@
#!/usr/bin/env ruby
# Wait for a sender connection, send a correct hello, then disconnect.
# Simulate a server which crashes after sending the hello. We then
# reopen the server socket to check that the sender retries: since the
# command-line has gone away, and can't feed an error back to the
# user, we have to keep trying.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept( "Timed out waiting for a connection" )
client.write_hello
client.close
new_client = server.accept( "Timed out waiting for a reconnection" )
new_client.close
server.close
exit 0

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
# encoding: utf-8
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept
client.write_hello
handle = client.read_request[:handle]
client.write_error( handle )
client2 = server.accept( "Timed out waiting for a reconnection" )
client.close
client2.close
server.close
exit(0)

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
# Will open a server, accept a single connection, then sleep for 5
# seconds. After that time, the client should have disconnected,
# which we can can't effectively check.
#
# This allows the test runner to check that the command-line sees the
# right error message after the timeout time.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept( "Client didn't make a connection" )
# Sleep for one second past the timeout (a bit of slop in case ruby
# doesn't launch things quickly)
sleep(FlexNBD::MS_HELLO_TIME_SECS + 1)
client.close
server.close

View File

@@ -0,0 +1,28 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a socket, say hello, receive a write, then sleep for >
# MS_REQUEST_LIMIT_SECS seconds. This should tell the source that the
# write has gone MIA, and we expect a reconnect.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client1 = server.accept( server )
client1.write_hello
client1.read_request
t = Thread.start do
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
client2.close
end
sleep( FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
client1.close
t.join
server.close
exit(0)

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env ruby
# Simulate a destination which sends the wrong magic.
# We expect the sender to disconnect and reconnect.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client1 = server.accept
# Launch a second thread so that we can spot the reconnection attempt
# as soon as it happens, or alternatively die a flaming death on
# timeout.
t = Thread.new do
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2.close
end
client1.write_hello( :magic => :wrong )
t.join
exit 0

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
# Simulate a server which has a disc of the wrong size attached: send
# a valid NBD hello with a random size, then check that we have see an
# EOF on read.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
client = server.accept
t = Thread.new do
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2.close
end
client.write_hello( :size => :wrong )
t.join
exit 0

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
# Accept a connection, then immediately close it. This simulates an ACL rejection.
require 'flexnbd/fake_dest'
include FlexNBD
server = FakeDest.new( *ARGV )
server.accept.close
server.close
exit(0)

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)