test: fix bulk-kick test case flakyness

This commit is contained in:
Zaiming (Stone) Shi 2023-11-30 17:30:25 +01:00
parent 5427ebc5f1
commit 81e75cf068
1 changed files with 25 additions and 1 deletions

View File

@ -214,7 +214,22 @@ t_kickout_clients(_) ->
{ok, C3} = emqtt:start_link(#{clientid => ClientId3}), {ok, C3} = emqtt:start_link(#{clientid => ClientId3}),
{ok, _} = emqtt:connect(C3), {ok, _} = emqtt:connect(C3),
timer:sleep(300), emqx_common_test_helpers:wait_for(
?FUNCTION_NAME,
?LINE,
fun() ->
try
[_] = emqx_cm:lookup_channels(ClientId1),
[_] = emqx_cm:lookup_channels(ClientId2),
[_] = emqx_cm:lookup_channels(ClientId3),
true
catch
error:badmatch ->
false
end
end,
2000
),
%% get /clients %% get /clients
ClientsPath = emqx_mgmt_api_test_util:api_path(["clients"]), ClientsPath = emqx_mgmt_api_test_util:api_path(["clients"]),
@ -233,6 +248,15 @@ t_kickout_clients(_) ->
KickoutBody = [ClientId1, ClientId2, ClientId3], KickoutBody = [ClientId1, ClientId2, ClientId3],
{ok, 204, _} = emqx_mgmt_api_test_util:request_api_with_body(post, KickoutPath, KickoutBody), {ok, 204, _} = emqx_mgmt_api_test_util:request_api_with_body(post, KickoutPath, KickoutBody),
ReceiveExit = fun({ClientPid, ClientId}) ->
receive
{'EXIT', Pid, _} when Pid =:= ClientPid ->
ok
after 1000 ->
error({timeout, ClientId})
end
end,
lists:foreach(ReceiveExit, [{C1, ClientId1}, {C2, ClientId2}, {C3, ClientId3}]),
{ok, Clients2} = emqx_mgmt_api_test_util:request_api(get, ClientsPath), {ok, Clients2} = emqx_mgmt_api_test_util:request_api(get, ClientsPath),
ClientsResponse2 = emqx_utils_json:decode(Clients2, [return_maps]), ClientsResponse2 = emqx_utils_json:decode(Clients2, [return_maps]),
?assertMatch(#{<<"meta">> := #{<<"count">> := 0}}, ClientsResponse2). ?assertMatch(#{<<"meta">> := #{<<"count">> := 0}}, ClientsResponse2).