From 6ffa10bf891ae7525ad6645b60c6134cccb35814 Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 20 Sep 2013 16:00:56 +0100 Subject: [PATCH] flexnbd: Make a test a bit stricter --- .../acceptance/test_write_during_migration.rb | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/test_write_during_migration.rb b/tests/acceptance/test_write_during_migration.rb index 26c19d7..dea8da6 100755 --- a/tests/acceptance/test_write_during_migration.rb +++ b/tests/acceptance/test_write_during_migration.rb @@ -35,22 +35,26 @@ 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 awaiting = nil Timeout.timeout(10) do awaiting = :source - sleep 0.1 while !File.exists?( @source_sock ) + sleep 0.1 while !File.exists?( @source_sock ) awaiting = :dest sleep 0.1 while !File.exists?( @dest_sock ) end @@ -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 } @@ -101,14 +105,15 @@ class TestWriteDuringMigration < Test::Unit::TestCase Dir.mktmpdir() do |tmpdir| Dir.chdir( tmpdir ) do make_files() - + launch_servers() 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 +