2012-07-03 13:33:52 +01:00
|
|
|
require 'test/unit'
|
|
|
|
require 'environment'
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
class TestDestErrorHandling < Test::Unit::TestCase
|
2012-07-03 13:33:52 +01:00
|
|
|
def setup
|
|
|
|
@env = Environment.new
|
2018-02-02 21:34:14 +00:00
|
|
|
@env.writefile1('0' * 4)
|
2012-07-03 13:33:52 +01:00
|
|
|
@env.listen1
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@env.cleanup
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_hello_blocked_by_disconnect_causes_error_not_fatal
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/close_after_connect')
|
2012-07-03 13:33:52 +01:00
|
|
|
assert_no_control
|
|
|
|
end
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
# # This is disabled while CLIENT_MAX_WAIT_SECS is removed
|
|
|
|
# def test_hello_goes_astray_causes_timeout_error
|
|
|
|
# run_fake( "source/hang_after_hello" )
|
|
|
|
# assert_no_control
|
|
|
|
# end
|
2012-07-03 13:33:52 +01:00
|
|
|
|
2012-10-04 14:41:55 +01:00
|
|
|
def test_sigterm_has_bad_exit_status
|
|
|
|
@env.nbd1.can_die(1)
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/sigterm_after_hello')
|
2012-10-04 14:41:55 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
def test_disconnect_after_hello_causes_error_not_fatal
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/close_after_hello')
|
2012-07-03 13:33:52 +01:00
|
|
|
assert_no_control
|
|
|
|
end
|
|
|
|
|
2012-07-12 14:14:46 +01:00
|
|
|
def test_partial_read_causes_error
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/close_mid_read')
|
2012-07-12 14:14:46 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
def test_double_connect_during_hello
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/connect_during_hello')
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_acl_rejection
|
2018-02-02 21:34:14 +00:00
|
|
|
@env.acl1('127.0.0.1')
|
|
|
|
run_fake('source/connect_from_banned_ip')
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_bad_write
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/write_out_of_range')
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 15:33:00 +01:00
|
|
|
def test_disconnect_before_write_data_causes_error
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/close_after_write')
|
2012-07-03 15:25:39 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 15:33:00 +01:00
|
|
|
def test_disconnect_before_write_reply_causes_error
|
|
|
|
# Note that this is an odd case: writing the reply doesn't fail.
|
|
|
|
# The test passes because the next attempt by flexnbd to read a
|
|
|
|
# request returns EOF.
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/close_after_write_data')
|
2012-07-03 15:33:00 +01:00
|
|
|
end
|
|
|
|
|
2012-07-23 09:48:50 +01:00
|
|
|
def test_straight_migration
|
|
|
|
@env.nbd1.can_die(0)
|
2018-02-02 21:34:14 +00:00
|
|
|
run_fake('source/successful_transfer')
|
2012-07-12 09:39:39 +01:00
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
private
|
2018-02-02 21:34:14 +00:00
|
|
|
|
|
|
|
def run_fake(name)
|
|
|
|
@env.run_fake(name, @env.ip, @env.port1)
|
2012-07-03 13:33:52 +01:00
|
|
|
assert @env.fake_reports_success, "#{name} failed."
|
|
|
|
end
|
|
|
|
|
2012-07-12 14:14:46 +01:00
|
|
|
def status
|
2018-02-02 21:34:14 +00:00
|
|
|
stat, = @env.status1
|
2012-07-12 14:14:46 +01:00
|
|
|
stat
|
|
|
|
end
|
|
|
|
|
2012-07-03 13:33:52 +01:00
|
|
|
def assert_no_control
|
2018-02-02 21:34:14 +00:00
|
|
|
assert !status['has_control'], 'Thought it had control'
|
2012-07-03 13:33:52 +01:00
|
|
|
end
|
|
|
|
|
2012-07-12 14:14:46 +01:00
|
|
|
def assert_control
|
|
|
|
assert status['has_control'], "Didn't think it had control"
|
|
|
|
end
|
2012-07-03 13:35:47 +01:00
|
|
|
end # class TestDestErrorHandling
|