2012-06-22 10:05:41 +01:00
|
|
|
#!/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.
|
|
|
|
#
|
2012-07-15 21:57:36 +01:00
|
|
|
# We also expect the client *not* to reconnect, since it could feed back
|
|
|
|
# an error.
|
|
|
|
#
|
2012-06-22 10:05:41 +01:00
|
|
|
# This allows the test runner to check that the command-line sees the
|
|
|
|
# right error message after the timeout time.
|
|
|
|
|
2012-06-28 11:34:36 +01:00
|
|
|
require 'flexnbd/fake_dest'
|
2012-07-02 15:04:45 +01:00
|
|
|
include FlexNBD
|
2012-06-22 10:05:41 +01:00
|
|
|
|
2012-07-03 15:25:39 +01:00
|
|
|
addr, port = *ARGV
|
|
|
|
server = FakeDest.new( addr, port )
|
2012-07-02 15:04:45 +01:00
|
|
|
client = server.accept( "Client didn't make a connection" )
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2012-07-02 15:04:45 +01:00
|
|
|
client.close
|
2012-07-15 21:57:36 +01:00
|
|
|
|
|
|
|
# Invert the sense of the timeout exception, since we *don't* want a
|
|
|
|
# connection attempt
|
|
|
|
begin
|
|
|
|
server.accept( "Expected timeout" )
|
|
|
|
fail "Unexpected reconnection"
|
|
|
|
rescue Timeout::Error
|
|
|
|
# expected
|
|
|
|
end
|
|
|
|
|
2012-07-02 15:04:45 +01:00
|
|
|
server.close
|