Files
flexnbd-c/tests/acceptance/test_source_error_handling.rb
Alex Young f3f017a87d Free all possibly held mutexes in error handlers
Now that we have 3 mutexes lying around, it's important that we check
and free these if necessary if error() is called in any thread that can
hold them.  To do this, we now have flexthread.c, which defines a
flexthread_mutex struct.  This is a wrapper around a pthread_mutex_t and
a pthread_t.  The idea is that in the error handler, the thread can
check whether it holds the mutex and can free it if and only if it does.
This is important because pthread fast mutexes can be freed by *any*
thread, not just the thread which holds them.

Note: it is only ever safe for a thread to check if it holds the mutex
itself.  It is *never* safe to check if another thread holds a mutex
without first locking that mutex, which makes the whole operation rather
pointless.
2012-07-11 09:43:16 +01:00

103 lines
2.0 KiB
Ruby

# encoding: utf-8
require 'test/unit'
require 'environment'
class TestSourceErrorHandling < Test::Unit::TestCase
def setup
@env = Environment.new
@env.writefile1( "f" * 4 )
@env.serve1
end
def teardown
@env.nbd1.can_die(0)
@env.cleanup
end
def test_failure_to_connect_reported_in_mirror_cmd_response
stdout, stderr = @env.mirror12_unchecked
assert_match( /failed to connect/, stderr )
end
def test_destination_hangs_after_connect_reports_error_at_source
run_fake( "dest/hang_after_connect",
/Remote server failed to respond/ )
end
def test_destination_rejects_connection_reports_error_at_source
run_fake( "dest/reject_acl",
/Mirror was rejected/ )
end
def test_wrong_size_causes_disconnect
run_fake( "dest/hello_wrong_size",
/Remote size does not match local size/ )
end
def test_wrong_magic_causes_disconnect
run_fake( "dest/hello_wrong_magic",
/Mirror was rejected/ )
end
def test_disconnect_after_hello_causes_retry
run_fake( "dest/close_after_hello",
/Mirror started/ )
end
def test_write_times_out_causes_retry
run_fake( "dest/hang_after_write" )
end
def test_rejected_write_causes_retry
run_fake( "dest/error_on_write" )
end
def test_disconnect_before_write_reply_causes_retry
run_fake( "dest/close_after_write" )
end
def test_bad_write_reply_causes_retry
run_fake( "dest/write_wrong_magic" )
end
def test_pre_entrust_disconnect_causes_retry
run_fake( "dest/close_after_writes" )
end
def test_post_entrust_disconnect_causes_retry
@env.nbd1.can_die(0)
run_fake( "dest/close_after_entrust" )
end
private
def run_fake(name, err=nil)
@env.run_fake( name, @env.ip, @env.port2 )
stdout, stderr = @env.mirror12_unchecked
assert_success
assert_match( err, stderr ) if err
return stdout, stderr
end
def assert_success( msg=nil )
assert @env.fake_reports_success, msg || "Fake failed"
end
end # class TestSourceErrorHandling