From d9bf51ea9803ec5aac8a587405157138dd729c2d Mon Sep 17 00:00:00 2001 From: David Ansari Date: Tue, 11 Mar 2025 16:58:59 +0100 Subject: [PATCH] Fix flake in test case session_upgrade_v3_v5_qos1 CI sometimes failed with the following error: ``` v5_SUITE:session_upgrade_v3_v5_qos failed on line 1068 Reason: {test_case_failed,Received unexpected PUBLISH payload. Expected: <<"2">> Got: <<"3">>} ``` The emqtt client auto acks by default. Therefore, if Subv3 client was able to successfully auto ack message 2 before Subv3 disconnected, Subv5 client did not receive message 2. This commit fixes this flake by making sure that Subv3 does not ack message 2. (cherry picked from commit 7cf076673b244cf4ee009c5691c801f60c43f99b) --- deps/rabbitmq_mqtt/test/v5_SUITE.erl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/deps/rabbitmq_mqtt/test/v5_SUITE.erl b/deps/rabbitmq_mqtt/test/v5_SUITE.erl index 30217857311f..a74cf0277bba 100644 --- a/deps/rabbitmq_mqtt/test/v5_SUITE.erl +++ b/deps/rabbitmq_mqtt/test/v5_SUITE.erl @@ -1020,17 +1020,27 @@ session_upgrade_v3_v5_qos0(Config) -> session_upgrade_v3_v5_qos(Qos, Config) -> ClientId = Topic = atom_to_binary(?FUNCTION_NAME), Pub = connect(<<"publisher">>, Config), - Subv3 = connect(ClientId, Config, [{proto_ver, v3} | non_clean_sess_opts()]), + Subv3 = connect(ClientId, Config, + [{proto_ver, v3}, + {auto_ack, false}] ++ + non_clean_sess_opts()), ?assertEqual(3, proplists:get_value(proto_ver, emqtt:info(Subv3))), {ok, _, [Qos]} = emqtt:subscribe(Subv3, Topic, Qos), Sender = spawn_link(?MODULE, send, [self(), Pub, Topic, 0]), receive {publish, #{payload := <<"1">>, - client_pid := Subv3}} -> ok + client_pid := Subv3, + packet_id := PacketId}} -> + case Qos of + 0 -> ok; + 1 -> emqtt:puback(Subv3, PacketId) + end after ?TIMEOUT -> ct:fail("did not receive 1") end, %% Upgrade session from v3 to v5 while another client is sending messages. ok = emqtt:disconnect(Subv3), - Subv5 = connect(ClientId, Config, [{proto_ver, v5}, {clean_start, false}]), + Subv5 = connect(ClientId, Config, [{proto_ver, v5}, + {clean_start, false}, + {auto_ack, true}]), ?assertEqual(5, proplists:get_value(proto_ver, emqtt:info(Subv5))), Sender ! stop, NumSent = receive {N, Sender} -> N