test(clients v2 api): attempt to reduce flakiness

https://github.com/emqx/emqx/actions/runs/10161391242/job/28101183920#step:6:331
This commit is contained in:
Thales Macedo Garitezi 2024-07-30 14:07:08 -03:00
parent 359bc38aa4
commit 1c4402b12c
1 changed files with 18 additions and 9 deletions

View File

@ -550,13 +550,10 @@ t_persistent_sessions5(Config) ->
lists:sort(lists:map(fun(#{<<"clientid">> := CId}) -> CId end, R3 ++ R4))
),
lists:foreach(fun emqtt:stop/1, [C3, C4]),
lists:foreach(
fun(ClientId) ->
ok = erpc:call(N1, emqx_persistent_session_ds, destroy_session, [ClientId])
end,
ClientIds
),
lists:foreach(fun disconnect_and_destroy_session/1, [C3, C4]),
C1B = connect_client(#{port => Port1, clientid => ClientId1}),
C2B = connect_client(#{port => Port2, clientid => ClientId2}),
lists:foreach(fun disconnect_and_destroy_session/1, [C1B, C2B]),
ok
end,
@ -1623,8 +1620,7 @@ t_list_clients_v2(Config) ->
port => Port2, clientid => ClientId6, expiry => 0, clean_start => true
}),
%% offline persistent clients
ok = emqtt:stop(C3),
ok = emqtt:stop(C4),
lists:foreach(fun stop_and_commit/1, [C3, C4]),
%% one by one
QueryParams1 = #{limit => "1"},
@ -2143,3 +2139,16 @@ do_traverse_in_reverse_v2(QueryParams0, Config, [Cursor | Rest], DirectOrderClie
disconnect_and_destroy_session(Client) ->
ok = emqtt:disconnect(Client, ?RC_SUCCESS, #{'Session-Expiry-Interval' => 0}).
%% To avoid a race condition where we try to delete the session while it's terminating and
%% committing. This shouldn't happen realistically, because we have a safe grace period
%% before attempting to GC a session.
%% Also, we need to wait until offline metadata is committed before checking the v2 client
%% list, to avoid flaky batch results.
stop_and_commit(Client) ->
{ok, {ok, _}} =
?wait_async_action(
emqtt:stop(Client),
#{?snk_kind := persistent_session_ds_terminate}
),
ok.