test: fix flaky banned case

since this suite has changed its start method to the `emqx_common_test_helpers:start_apps/1`, the `emqx_banned` server will never stop (its restart type is permanent), thus there is no need to manually start or stops it.
This commit is contained in:
firest 2022-11-17 14:29:03 +08:00
parent 8e87bd625d
commit 7b93b166dc
1 changed files with 22 additions and 14 deletions

View File

@ -97,22 +97,30 @@ t_check(_) ->
?assertEqual(0, emqx_banned:info(size)).
t_unused(_) ->
catch emqx_banned:stop(),
{ok, Banned} = emqx_banned:start_link(),
{ok, _} = emqx_banned:create(#banned{
who = {clientid, <<"BannedClient1">>},
Who1 = {clientid, <<"BannedClient1">>},
Who2 = {clientid, <<"BannedClient2">>},
?assertMatch(
{ok, _},
emqx_banned:create(#banned{
who = Who1,
until = erlang:system_time(second)
}),
{ok, _} = emqx_banned:create(#banned{
who = {clientid, <<"BannedClient2">>},
})
),
?assertMatch(
{ok, _},
emqx_banned:create(#banned{
who = Who2,
until = erlang:system_time(second) - 1
}),
?assertEqual(ignored, gen_server:call(Banned, unexpected_req)),
?assertEqual(ok, gen_server:cast(Banned, unexpected_msg)),
?assertEqual(ok, Banned ! ok),
})
),
?assertEqual(ignored, gen_server:call(emqx_banned, unexpected_req)),
?assertEqual(ok, gen_server:cast(emqx_banned, unexpected_msg)),
%% expiry timer
timer:sleep(500),
ok = emqx_banned:stop().
ok = emqx_banned:delete(Who1),
ok = emqx_banned:delete(Who2).
t_kick(_) ->
ClientId = <<"client">>,