2012-07-03 13:33:52 +01:00
|
|
|
require 'test/unit'
|
|
|
|
require 'environment'
|
|
|
|
|
|
|
|
class TestSourceErrorHandling < Test::Unit::TestCase
|
|
|
|
def setup
|
2013-10-30 22:45:12 +00:00
|
|
|
@old_env = ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS']
|
2018-02-02 21:34:14 +00:00
|
|
|
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'] = '4.0'
|
2013-10-30 22:45:12 +00:00
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
@env = Environment.new
|
2018-02-02 21:34:14 +00:00
|
|
|
@env.writefile1('f' * 4)
|
2012-07-03 13:33:52 +01:00
|
|
|
@env.serve1
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@env.nbd1.can_die(0)
|
|
|
|
@env.cleanup
|
2013-10-30 22:45:12 +00:00
|
|
|
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'] = @old_env
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2012-10-04 14:41:55 +01:00
|
|
|
def expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
@env.nbd1.can_die(1, 9)
|
2012-10-04 14:41:55 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
def test_failure_to_connect_reported_in_mirror_cmd_response
|
|
|
|
stdout, stderr = @env.mirror12_unchecked
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
assert_match(/failed to connect/, stderr)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2012-10-04 14:41:55 +01:00
|
|
|
def test_sigterm_after_hello_quits_with_status_of_1
|
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/sigterm_after_hello')
|
2012-10-04 14:41:55 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
def test_destination_hangs_after_connect_reports_error_at_source
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/hang_after_connect',
|
|
|
|
err: /Remote server failed to respond/)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_destination_rejects_connection_reports_error_at_source
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/reject_acl',
|
|
|
|
err: /Mirror was rejected/)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wrong_size_causes_disconnect
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/hello_wrong_size',
|
|
|
|
err: /Remote size does not match local size/)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_wrong_magic_causes_disconnect
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/hello_wrong_magic',
|
|
|
|
err: /Mirror was rejected/)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_disconnect_after_hello_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/close_after_hello',
|
|
|
|
out: /Mirror started/)
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_write_times_out_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/hang_after_write')
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejected_write_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/error_on_write')
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 14:52:27 +01:00
|
|
|
def test_disconnect_before_write_reply_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/close_after_write')
|
2012-07-03 14:52:27 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 17:01:39 +01:00
|
|
|
def test_bad_write_reply_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/write_wrong_magic')
|
2012-07-03 17:01:39 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 18:00:31 +01:00
|
|
|
def test_pre_entrust_disconnect_causes_retry
|
2012-10-04 14:41:55 +01:00
|
|
|
expect_term_during_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/close_after_writes')
|
2012-07-11 09:43:16 +01:00
|
|
|
end
|
|
|
|
|
2012-07-17 16:30:49 +01:00
|
|
|
def test_cancel_migration
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('dest/break_after_hello')
|
2012-07-17 16:30:49 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
private
|
2018-02-02 21:34:14 +00:00
|
|
|
|
2012-07-11 10:12:10 +01:00
|
|
|
def run_fake(name, opts = {})
|
2018-02-02 21:34:14 +00:00
|
|
|
@env.run_fake(name, @env.ip, @env.port2, @env.nbd1.ctrl)
|
2012-07-11 09:43:16 +01:00
|
|
|
stdout, stderr = @env.mirror12_unchecked
|
|
|
|
assert_success
|
2018-02-02 21:34:14 +00:00
|
|
|
assert_match(opts[:err], stderr) if opts[:err]
|
|
|
|
assert_match(opts[:out], stdout) if opts[:out]
|
|
|
|
[stdout, stderr]
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
def assert_success(msg = nil)
|
|
|
|
assert @env.fake_reports_success, msg || 'Fake failed'
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
2012-07-03 13:35:47 +01:00
|
|
|
end # class TestSourceErrorHandling
|