2012-06-22 10:05:41 +01:00
|
|
|
#!/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.
|
|
|
|
|
2012-06-28 11:34:36 +01:00
|
|
|
require 'flexnbd/fake_dest'
|
2012-07-02 15:04:45 +01:00
|
|
|
include FlexNBD
|
2012-07-15 20:07:17 +01:00
|
|
|
Thread.abort_on_exception = true
|
2012-06-28 11:34:36 +01:00
|
|
|
|
2012-07-03 15:25:39 +01:00
|
|
|
addr, port = *ARGV
|
2018-02-02 21:34:14 +00:00
|
|
|
server = FakeDest.new(addr, port)
|
2012-07-02 15:04:45 +01:00
|
|
|
client = server.accept
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
t = Thread.new do
|
2012-07-15 20:07:17 +01:00
|
|
|
# The sender *should not reconnect.* Since this is a first-pass
|
|
|
|
# mirror attempt, the user will have been told that the mirror failed,
|
|
|
|
# so it makes no sense to continue. This means we have to invert the
|
|
|
|
# sense of the exception.
|
|
|
|
begin
|
2018-02-02 21:34:14 +00:00
|
|
|
client2 = server.accept('Timed out waiting for a reconnection',
|
|
|
|
FlexNBD::MS_RETRY_DELAY_SECS + 1)
|
2012-07-15 20:07:17 +01:00
|
|
|
client2.close
|
2018-02-02 21:34:14 +00:00
|
|
|
raise 'Unexpected reconnection.'
|
2012-07-15 20:07:17 +01:00
|
|
|
rescue Timeout::Error
|
|
|
|
end
|
2012-06-22 10:05:41 +01:00
|
|
|
end
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
client.write_hello(size: :wrong)
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
t.join
|
|
|
|
|
2012-07-15 18:30:20 +01:00
|
|
|
# Now check that the source closed the first socket (yes, this was an
|
|
|
|
# actual bug)
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
raise "Didn't close socket" unless client.disconnected?
|
2012-07-15 18:30:20 +01:00
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
exit 0
|