flexnbd: Make a test a bit stricter
This commit is contained in:
@@ -35,15 +35,19 @@ class TestWriteDuringMigration < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def debug_arg
|
||||
ENV['DEBUG'] ? "--verbose" : ""
|
||||
end
|
||||
|
||||
|
||||
def launch_servers
|
||||
@dst_proc = fork() {
|
||||
cmd = "#{@flexnbd} listen -l 127.0.0.1 -p #{@dest_port} -f #{@dest_file} -s #{@dest_sock}"
|
||||
cmd = "#{@flexnbd} listen -l 127.0.0.1 -p #{@dest_port} -f #{@dest_file} -s #{@dest_sock} #{debug_arg}"
|
||||
exec cmd
|
||||
}
|
||||
|
||||
@src_proc = fork() {
|
||||
cmd = "#{@flexnbd} serve -l 127.0.0.1 -p #{@source_port} -f #{@source_file} -s #{@source_sock}"
|
||||
cmd = "#{@flexnbd} serve -l 127.0.0.1 -p #{@source_port} -f #{@source_file} -s #{@source_sock} #{debug_arg}"
|
||||
exec cmd
|
||||
}
|
||||
begin
|
||||
@@ -79,7 +83,7 @@ class TestWriteDuringMigration < Test::Unit::TestCase
|
||||
|
||||
def start_mirror
|
||||
UNIXSocket.open(@source_sock) {|sock|
|
||||
sock.write(["mirror", "127.0.0.1", @dest_port.to_s, "unlink"].join("\x0A") + "\x0A\x0A")
|
||||
sock.write(["mirror", "127.0.0.1", @dest_port.to_s, "exit"].join("\x0A") + "\x0A\x0A")
|
||||
sock.flush
|
||||
rsp = sock.readline
|
||||
}
|
||||
@@ -106,9 +110,10 @@ class TestWriteDuringMigration < Test::Unit::TestCase
|
||||
|
||||
src_writer = Thread.new do
|
||||
client = FlexNBD::FakeSource.new( "127.0.0.1", @source_port, "Timed out connecting" )
|
||||
offsets = Range.new(0, (@size - @write_data.size) / 4096 ).to_a
|
||||
loop do
|
||||
begin
|
||||
client.write(0, @write_data)
|
||||
client.write(offsets[rand(offsets.size)] * 4096, @write_data)
|
||||
rescue => err
|
||||
# We expect a broken write at some point, so ignore it
|
||||
break
|
||||
@@ -119,9 +124,25 @@ class TestWriteDuringMigration < Test::Unit::TestCase
|
||||
start_mirror()
|
||||
wait_for_quit()
|
||||
src_writer.join
|
||||
|
||||
# Ensure each block matches
|
||||
File.open(@source_file, "r") do |source|
|
||||
File.open(@dest_file, "r") do |dest|
|
||||
0.upto( @size / 4096 ) do |block_num|
|
||||
s_data = source.read( 4096 )
|
||||
d_data = source.read( 4096 )
|
||||
|
||||
assert s_data == d_data, "Block #{block_num} mismatch!"
|
||||
|
||||
source.seek( 4096, IO::SEEK_CUR )
|
||||
dest.seek( 4096, IO::SEEK_CUR )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user