diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2010-07-28 17:36:27 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2010-07-28 17:36:27 +0100 |
commit | 04d6a61e59cbc56c6f33cd7226948b34c2c787ab (patch) | |
tree | 3603be18c778b7bd6bb74c897f05348b644e4836 | |
parent | 949a030c38494e83124ed7f7e169cb865a255dda (diff) | |
download | rabbitmq-server-04d6a61e59cbc56c6f33cd7226948b34c2c787ab.tar.gz |
Clean up tests a bit, avoid the retry count and sleeping.
-rw-r--r-- | src/rabbit_channel.erl | 8 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 31 |
2 files changed, 21 insertions, 18 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 7d45cec9..67809880 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -38,7 +38,7 @@ -export([start_link/6, do/2, do/3, shutdown/1]). -export([send_command/2, deliver/4, conserve_memory/2, flushed/2]). -export([list/0, info_keys/0, info/1, info/2, info_all/0, info_all/1]). --export([emit_stats/1]). +-export([emit_stats/1, flush/1]). -export([flow_timeout/2]). @@ -160,6 +160,9 @@ info_all(Items) -> emit_stats(Pid) -> gen_server2:pcast(Pid, 7, emit_stats). +flush(Pid) -> + gen_server2:call(Pid, flush). + %%--------------------------------------------------------------------------- init([Channel, ReaderPid, WriterPid, Username, VHost, CollectorPid]) -> @@ -204,6 +207,9 @@ handle_call({info, Items}, _From, State) -> catch Error -> reply({error, Error}, State) end; +handle_call(flush, _from, State) -> + reply(ok, State); + handle_call(_Request, _From, State) -> noreply(State). diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 33c6ee5e..d2dca4a2 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -1181,19 +1181,16 @@ test_statistics_event_receiver(Pid) -> test_statistics_event_receiver(Pid) end. -test_statistics_receive_event(Ch, Retries, Matcher) -> +test_statistics_receive_event(Ch, Matcher) -> + rabbit_channel:flush(Ch), rabbit_channel:emit_stats(Ch), + test_statistics_receive_event1(Ch, Matcher). + +test_statistics_receive_event1(Ch, Matcher) -> receive #event{type = channel_stats, props = Props} -> case Matcher(Props) of - true -> - Props; - _ -> - case Retries of - 0 -> throw(failed_to_receive_matching_event); - _ -> timer:sleep(10), - test_statistics_receive_event(Ch, Retries - 1, - Matcher) - end + true -> Props; + _ -> test_statistics_receive_event1(Ch, Matcher) end after 1000 -> throw(failed_to_receive_event) end. @@ -1203,11 +1200,11 @@ test_statistics() -> %% ATM this just tests the queue / exchange stats in channels. That's %% by far the most complex code though. - + %% Set up a channel and queue {_Writer, Ch, _MRef} = test_spawn(fun test_statistics_receiver/1), rabbit_channel:do(Ch, #'queue.declare'{}), - QName = receive #'queue.declare_ok'{queue = Q0} -> + QName = receive #'queue.declare_ok'{queue = Q0} -> Q0 after 1000 -> throw(failed_to_receive_queue_declare_ok) end, @@ -1216,13 +1213,13 @@ test_statistics() -> X = rabbit_misc:r(<<"/">>, exchange, <<"">>), rabbit_tests_event_receiver:start(self()), - + %% Check stats empty - Event = test_statistics_receive_event(Ch, 0, fun (_) -> true end), + Event = test_statistics_receive_event(Ch, fun (_) -> true end), [] = proplists:get_value(channel_queue_stats, Event), [] = proplists:get_value(channel_exchange_stats, Event), [] = proplists:get_value(channel_queue_exchange_stats, Event), - + %% Publish and get a message rabbit_channel:do(Ch, #'basic.publish'{exchange = <<"">>, routing_key = QName}, @@ -1231,7 +1228,7 @@ test_statistics() -> %% Check the stats reflect that Event2 = test_statistics_receive_event( - Ch, 10, + Ch, fun (E) -> length(proplists:get_value( channel_queue_exchange_stats, E)) > 0 @@ -1244,7 +1241,7 @@ test_statistics() -> %% Check the stats remove stuff on queue deletion rabbit_channel:do(Ch, #'queue.delete'{queue = QName}), Event3 = test_statistics_receive_event( - Ch, 10, + Ch, fun (E) -> length(proplists:get_value( channel_queue_exchange_stats, E)) == 0 |