This commit is contained in:
Patrick J Cherry
2018-02-02 21:34:14 +00:00
parent 1b7b688f7a
commit 9c48da82cc
40 changed files with 666 additions and 858 deletions

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a server, accept a client, then cancel the migration by issuing
# a break command.
@@ -8,28 +6,27 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid, sock = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
ctrl = UNIXSocket.open( sock )
ctrl = UNIXSocket.open(sock)
Process.kill("STOP", src_pid.to_i)
ctrl.write( "break\n" )
Process.kill('STOP', src_pid.to_i)
ctrl.write("break\n")
ctrl.close_write
client.write_hello
Process.kill("CONT", src_pid.to_i)
Process.kill('CONT', src_pid.to_i)
fail "Unexpected control response" unless
raise 'Unexpected control response' unless
ctrl.read =~ /0: mirror stopped/
client2 = nil
begin
client2 = server.accept( "Expected timeout" )
fail "Unexpected reconnection"
client2 = server.accept('Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end
client.close
exit(0)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Receive a mirror, and disconnect after sending the entrust reply but
# before it can send the disconnect signal.
#
@@ -11,26 +9,25 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
while (req = client.read_request; req[:type] == 1)
client.read_data( req[:len] )
client.write_reply( req[:handle] )
while req = client.read_request; req[:type] == 1
client.read_data(req[:len])
client.write_reply(req[:handle])
end
system "kill -STOP #{src_pid}"
client.write_reply( req[:handle] )
client.write_reply(req[:handle])
client.close
system "kill -CONT #{src_pid}"
sleep( 0.25 )
client2 = server.accept( "Timed out waiting for a reconnection" )
sleep(0.25)
client2 = server.accept('Timed out waiting for a reconnection')
client2.close
server.close
$stderr.puts "done"
warn 'done'
exit(0)

View File

@@ -10,12 +10,12 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
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 = server.accept('Timed out waiting for a reconnection')
new_client.close
server.close

View File

@@ -11,13 +11,13 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
client = server.accept('Timed out waiting for a connection')
client.write_hello
client.read_request
client.close
new_client = server.accept( "Timed out waiting for a reconnection" )
new_client = server.accept('Timed out waiting for a reconnection')
new_client.close
server.close

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a server, accept a client, then we expect a single write
# followed by an entrust. However, we disconnect after the write so
# the entrust will fail. We don't expect a reconnection: the sender
@@ -10,16 +8,16 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
req = client.read_request
data = client.read_data( req[:len] )
data = client.read_data(req[:len])
Process.kill("STOP", src_pid.to_i)
client.write_reply( req[:handle], 0 )
Process.kill('STOP', src_pid.to_i)
client.write_reply(req[:handle], 0)
client.close
Process.kill("CONT", src_pid.to_i)
Process.kill('CONT', src_pid.to_i)
exit(0)

View File

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

View File

@@ -14,8 +14,8 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Client didn't make a connection" )
server = FakeDest.new(addr, port)
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)
@@ -26,10 +26,10 @@ client.close
# Invert the sense of the timeout exception, since we *don't* want a
# connection attempt
begin
server.accept( "Expected timeout" )
fail "Unexpected reconnection"
server.accept('Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
# expected
end
server.close

View File

@@ -1,6 +1,4 @@
#!/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.
@@ -9,24 +7,24 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client1 = server.accept( server )
server = FakeDest.new(addr, port)
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 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_REQUEST_LIMIT_SECS + 2)
client2.close
end
sleep_time = if ENV.has_key?('FLEXNBD_MS_REQUEST_LIMIT_SECS')
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'].to_f
else
FlexNBD::MS_REQUEST_LIMIT_SECS
sleep_time = if ENV.key?('FLEXNBD_MS_REQUEST_LIMIT_SECS')
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'].to_f
else
FlexNBD::MS_REQUEST_LIMIT_SECS
end
sleep( sleep_time + 2.0 )
sleep(sleep_time + 2.0)
client1.close
t.join

View File

@@ -7,21 +7,21 @@ include FlexNBD
Thread.abort_on_exception
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client1 = server.accept
# We don't expect a reconnection attempt.
t = Thread.new do
begin
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
fail "Unexpected reconnection"
client2 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_RETRY_DELAY_SECS + 1)
raise 'Unexpected reconnection'
rescue Timeout::Error
#expected
# expected
end
end
client1.write_hello( :magic => :wrong )
client1.write_hello(magic: :wrong)
t.join

View File

@@ -9,7 +9,7 @@ include FlexNBD
Thread.abort_on_exception = true
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
t = Thread.new do
@@ -18,21 +18,21 @@ t = Thread.new do
# so it makes no sense to continue. This means we have to invert the
# sense of the exception.
begin
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_RETRY_DELAY_SECS + 1)
client2.close
fail "Unexpected reconnection."
raise 'Unexpected reconnection.'
rescue Timeout::Error
end
end
client.write_hello( :size => :wrong )
client.write_hello(size: :wrong)
t.join
# Now check that the source closed the first socket (yes, this was an
# actual bug)
fail "Didn't close socket" unless client.disconnected?
raise "Didn't close socket" unless client.disconnected?
exit 0

View File

@@ -7,18 +7,16 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
server.accept.close
begin
server.accept
fail "Unexpected reconnection"
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end
server.close
exit(0)

View File

@@ -8,8 +8,8 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, pid = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
client = server.accept('Timed out waiting for a connection')
client.write_hello
Process.kill(15, pid.to_i)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Accept a connection, write hello, wait for a write request, read the
# data, then write back a reply with a bad magic field. We then
# expect a reconnect.
@@ -9,13 +7,13 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
req = client.read_request
client.read_data( req[:len] )
client.write_reply( req[:handle], 0, :magic => :wrong )
client.read_data(req[:len])
client.write_reply(req[:handle], 0, magic: :wrong)
client2 = server.accept
client.close