Skip to content

Commit b15d151

Browse files
Head message timestamp: make the test more robust
(cherry picked from commit aea77c7)
1 parent 6c6ff7e commit b15d151

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

test/unit_inbroker_non_parallel_SUITE.erl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
-module(unit_inbroker_non_parallel_SUITE).
1818

19+
-include_lib("eunit/include/eunit.hrl").
1920
-include_lib("common_test/include/ct.hrl").
2021
-include_lib("kernel/include/file.hrl").
2122
-include_lib("amqp_client/include/amqp_client.hrl").
@@ -570,8 +571,9 @@ head_message_timestamp_statistics(Config) ->
570571
?MODULE, head_message_timestamp1, [Config]).
571572

572573
head_message_timestamp1(_Config) ->
573-
%% Can't find a way to receive the ack here so can't test pending acks status
574-
574+
%% there is no convenient rabbit_channel API for confirms
575+
%% this test could use, so it relies on tx.* methods
576+
%% and gen_server2 flushing
575577
application:set_env(rabbit, collect_statistics, fine),
576578

577579
%% Set up a channel and queue
@@ -592,20 +594,30 @@ head_message_timestamp1(_Config) ->
592594
Event1 = test_queue_statistics_receive_event(QPid, fun (E) -> proplists:get_value(name, E) == QRes end),
593595
'' = proplists:get_value(head_message_timestamp, Event1),
594596

597+
rabbit_channel:do(Ch, #'tx.select'{}),
598+
receive #'tx.select_ok'{} -> ok
599+
after ?TIMEOUT -> throw(failed_to_receive_tx_select_ok)
600+
end,
601+
595602
%% Publish two messages and check timestamp is that of first message
596603
rabbit_channel:do(Ch, #'basic.publish'{exchange = <<"">>,
597604
routing_key = QName},
598605
rabbit_basic:build_content(#'P_basic'{timestamp = 1}, <<"">>)),
599606
rabbit_channel:do(Ch, #'basic.publish'{exchange = <<"">>,
600607
routing_key = QName},
601608
rabbit_basic:build_content(#'P_basic'{timestamp = 2}, <<"">>)),
609+
rabbit_channel:do(Ch, #'tx.commit'{}),
610+
rabbit_channel:flush(Ch),
611+
receive #'tx.commit_ok'{} -> ok
612+
after ?TIMEOUT -> throw(failed_to_receive_tx_commit_ok)
613+
end,
602614
Event2 = test_queue_statistics_receive_event(QPid, fun (E) -> proplists:get_value(name, E) == QRes end),
603-
1 = proplists:get_value(head_message_timestamp, Event2),
615+
?assertEqual(1, proplists:get_value(head_message_timestamp, Event2)),
604616

605617
%% Get first message and check timestamp is that of second message
606618
rabbit_channel:do(Ch, #'basic.get'{queue = QName, no_ack = true}),
607619
Event3 = test_queue_statistics_receive_event(QPid, fun (E) -> proplists:get_value(name, E) == QRes end),
608-
2 = proplists:get_value(head_message_timestamp, Event3),
620+
?assertEqual(2, proplists:get_value(head_message_timestamp, Event3)),
609621

610622
%% Get second message and check timestamp is empty again
611623
rabbit_channel:do(Ch, #'basic.get'{queue = QName, no_ack = true}),

0 commit comments

Comments
 (0)