diff options
author | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-03-06 12:45:40 +0000 |
---|---|---|
committer | Alexandru Scvortov <alexandru@rabbitmq.com> | 2011-03-06 12:45:40 +0000 |
commit | 282e6115095e9ed2a60c2b9f5858ff2db17d7d3a (patch) | |
tree | f426d92835ae3196c99c8ea5c4b3666310d09ebd | |
parent | 163d45122ee547c2361193939ca41f624b70f366 (diff) | |
download | rabbitmq-server-282e6115095e9ed2a60c2b9f5858ff2db17d7d3a.tar.gz |
add test for confirms in case of queue death
There's a race in the test, but it seems to work reliably. I ran it
1000 times in isolation and it didn't fail.
-rw-r--r-- | src/rabbit_tests.erl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 88b58166..4ad35696 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -57,6 +57,7 @@ all_tests() -> passed = test_cluster_management(), passed = test_user_management(), passed = test_server_status(), + passed = test_confirms(), passed = maybe_run_cluster_dependent_tests(), passed = test_configurable_server_properties(), passed. @@ -1225,6 +1226,79 @@ test_statistics_receive_event1(Ch, Matcher) -> after 1000 -> throw(failed_to_receive_event) end. +test_confirms_receiver(Pid) -> + receive + shutdown -> + ok; + {send_command, Method} -> + Pid ! Method, + test_confirms_receiver(Pid) + end. + +test_confirms() -> + {_Writer, Ch} = test_spawn(fun test_confirms_receiver/1), + DeclareBindDurableQueue = + fun() -> + rabbit_channel:do(Ch, #'queue.declare'{durable = true}), + receive #'queue.declare_ok'{queue = Q0} -> + rabbit_channel:do(Ch, #'queue.bind'{ + queue = Q0, + exchange = <<"amq.direct">>, + routing_key = "magic" }), + receive #'queue.bind_ok'{} -> + Q0 + after 1000 -> + throw(failed_to_bind_queue) + end + after 1000 -> + throw(failed_to_declare_queue) + end + end, + %% Declare and bind two queues + QName1 = DeclareBindDurableQueue(), + QName2 = DeclareBindDurableQueue(), + %% Get the first one's pid (we'll crash it later) + {ok, Q1} = rabbit_amqqueue:lookup(rabbit_misc:r(<<"/">>, queue, QName1)), + QPid1 = Q1#amqqueue.pid, + %% Enable confirms + rabbit_channel:do(Ch, #'confirm.select'{}), + receive #'confirm.select_ok'{} -> + ok + after 1000 -> + throw(failed_to_enable_confirms) + end, + %% Publish a message + rabbit_channel:do(Ch, #'basic.publish'{exchange = <<"amq.direct">>, + routing_key = "magic" + }, + rabbit_basic:build_content( + #'P_basic'{delivery_mode = 2}, <<"">>)), + %% Crash the queue + QPid1 ! boom, + %% Wait for a nack + receive + #'basic.nack'{} -> + ok; + #'basic.ack'{} -> + throw(received_ack_instead_of_nack) + after 2000 -> + throw(did_not_receive_nack) + end, + receive + #'basic.ack'{} -> + throw(received_ack_when_none_expected) + after 1000 -> + ok + end, + %% Delete queue + rabbit_channel:do(Ch, #'queue.delete'{queue = QName2}), + receive #'queue.delete_ok'{} -> + ok + after 1000 -> + throw(failed_to_cleanup_queue) + end, + passed. + test_statistics() -> application:set_env(rabbit, collect_statistics, fine), |