Update this test to use a consumer in a separate process

This commit is contained in:
Michael Klishin 2019-11-26 12:23:40 +03:00
parent f550aa0706
commit 6e17eeb3c5
1 changed files with 24 additions and 4 deletions

View File

@ -82,11 +82,15 @@ init_per_group(with_metrics, Config0) ->
#amqp_msg{payload = <<"msg">>}), #amqp_msg{payload = <<"msg">>}),
timer:sleep(150), timer:sleep(150),
{#'basic.get_ok'{}, #amqp_msg{}} = amqp_channel:call(Ch, #'basic.get'{queue = Q}), {#'basic.get_ok'{}, #amqp_msg{}} = amqp_channel:call(Ch, #'basic.get'{queue = Q}),
% We want to check consumer metrics, so we need at least 1 consumer bound %% We want to check consumer metrics, so we need at least 1 consumer bound
#'basic.consume_ok'{consumer_tag = CTag} = amqp_channel:call(Ch, #'basic.consume'{queue = Q}), %% but we don't care what it does if anything as long as the runner process does
%% not have to handle the consumer's messages.
ConsumerPid = sleeping_consumer(),
#'basic.consume_ok'{consumer_tag = CTag} =
amqp_channel:subscribe(Ch, #'basic.consume'{queue = Q}, ConsumerPid),
timer:sleep(10000), timer:sleep(10000),
Config2 ++ [{channel_pid, Ch}, {queue_name, Q}, {consumer_tag, CTag}]. Config2 ++ [{channel_pid, Ch}, {queue_name, Q}, {consumer_tag, CTag}, {consumer_pid, ConsumerPid}].
init_per_group(Group, Config0, Extra) -> init_per_group(Group, Config0, Extra) ->
rabbit_ct_helpers:log_environment(), rabbit_ct_helpers:log_environment(),
@ -99,7 +103,9 @@ init_per_group(Group, Config0, Extra) ->
end_per_group(with_metrics, Config) -> end_per_group(with_metrics, Config) ->
Ch = ?config(channel_pid, Config), Ch = ?config(channel_pid, Config),
CTag = ?config(consumer_tag, Config), CTag = ?config(consumer_tag, Config),
#'basic.cancel_ok'{} = amqp_channel:call(Ch, #'basic.cancel'{consumer_tag = CTag}), amqp_channel:call(Ch, #'basic.cancel'{consumer_tag = CTag}),
ConsumerPid = ?config(consumer_pid, Config),
ConsumerPid ! stop,
amqp_channel:call(Ch, #'queue.delete'{queue = ?config(queue_name, Config)}), amqp_channel:call(Ch, #'queue.delete'{queue = ?config(queue_name, Config)}),
rabbit_ct_client_helpers:close_channel(Ch), rabbit_ct_client_helpers:close_channel(Ch),
end_per_group_(Config); end_per_group_(Config);
@ -117,6 +123,20 @@ init_per_testcase(Testcase, Config) ->
end_per_testcase(Testcase, Config) -> end_per_testcase(Testcase, Config) ->
rabbit_ct_helpers:testcase_finished(Config, Testcase). rabbit_ct_helpers:testcase_finished(Config, Testcase).
%% a no-op consumer
sleeping_consumer_loop() ->
receive
stop -> ok;
#'basic.consume_ok'{} -> sleeping_consumer_loop();
#'basic.consume_ok'{} -> sleeping_consumer_loop();
{#'basic.deliver'{}, _Payload} -> sleeping_consumer_loop()
end.
sleeping_consumer() ->
spawn(fun() ->
sleeping_consumer_loop()
end).
%% ------------------------------------------------------------------- %% -------------------------------------------------------------------
%% Testcases. %% Testcases.
%% ------------------------------------------------------------------- %% -------------------------------------------------------------------