From ec6e8625390839905c34e874046b8e8896808893 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Fri, 28 Jun 2024 15:40:55 -0300 Subject: [PATCH] test(authz cache): attempt to fix flaky test Hypothesis: some race condition involving the previous test case, which uses the same clientid. ``` Testing apps.emqx.emqx_authz_cache_SUITE: *** FAILED test case 3 of 3 *** %%% emqx_authz_cache_SUITE ==> t_drain_authz_cache: FAILED %%% emqx_authz_cache_SUITE ==> Failure/Error: ?assertEqual([], list_cache ( ClientPid )) expected: [] got: [{{#{qos => 0,action_type => publish,retain => false},<<"t1">>}, {allow,1719599365019}}] line: 72 ``` --- apps/emqx/test/emqx_authz_cache_SUITE.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/emqx/test/emqx_authz_cache_SUITE.erl b/apps/emqx/test/emqx_authz_cache_SUITE.erl index 90759f62e..307cf6f57 100644 --- a/apps/emqx/test/emqx_authz_cache_SUITE.erl +++ b/apps/emqx/test/emqx_authz_cache_SUITE.erl @@ -37,7 +37,7 @@ end_per_suite(Config) -> %%-------------------------------------------------------------------- t_cache_exclude(_) -> - ClientId = <<"test-id1">>, + ClientId = atom_to_binary(?FUNCTION_NAME), {ok, Client} = emqtt:start_link([{clientid, ClientId}]), {ok, _} = emqtt:connect(Client), {ok, _, _} = emqtt:subscribe(Client, <<"nocache/+/#">>, 0), @@ -47,11 +47,12 @@ t_cache_exclude(_) -> emqtt:stop(Client). t_clean_authz_cache(_) -> - {ok, Client} = emqtt:start_link([{clientid, <<"emqx_c">>}]), + ClientId = atom_to_binary(?FUNCTION_NAME), + {ok, Client} = emqtt:start_link([{clientid, ClientId}]), {ok, _} = emqtt:connect(Client), {ok, _, _} = emqtt:subscribe(Client, <<"t2">>, 0), emqtt:publish(Client, <<"t1">>, <<"{\"x\":1}">>, 0), - ClientPid = find_client_pid(<<"emqx_c">>), + ClientPid = find_client_pid(ClientId), Caches = list_cache(ClientPid), ct:log("authz caches: ~p", [Caches]), ?assert(length(Caches) > 0), @@ -60,11 +61,12 @@ t_clean_authz_cache(_) -> emqtt:stop(Client). t_drain_authz_cache(_) -> - {ok, Client} = emqtt:start_link([{clientid, <<"emqx_c">>}]), + ClientId = atom_to_binary(?FUNCTION_NAME), + {ok, Client} = emqtt:start_link([{clientid, ClientId}]), {ok, _} = emqtt:connect(Client), {ok, _, _} = emqtt:subscribe(Client, <<"t2">>, 0), emqtt:publish(Client, <<"t1">>, <<"{\"x\":1}">>, 0), - ClientPid = find_client_pid(<<"emqx_c">>), + ClientPid = find_client_pid(ClientId), Caches = list_cache(ClientPid), ct:log("authz caches: ~p", [Caches]), ?assert(length(Caches) > 0),