fix: update testcase t_discard_session_race

This commit is contained in:
Shawn 2023-03-24 11:40:36 +08:00
parent 071162ed4c
commit 2e50985f35
2 changed files with 10 additions and 3 deletions

View File

@ -84,6 +84,10 @@
, get_connected_client_count/0 , get_connected_client_count/0
]). ]).
-ifdef(TEST).
-export([request_stepdown/3]).
-endif.
-type(chan_pid() :: pid()). -type(chan_pid() :: pid()).
%% Tables for channel management. %% Tables for channel management.

View File

@ -314,16 +314,19 @@ flush_emqx_pool() ->
t_discard_session_race(_) -> t_discard_session_race(_) ->
ClientId = rand_client_id(), ClientId = rand_client_id(),
ConnMod = emqx_ws_connection,
?check_trace( ?check_trace(
begin begin
#{conninfo := ConnInfo0} = ?ChanInfo, #{conninfo := ConnInfo0} = ?ChanInfo,
ConnInfo = ConnInfo0#{conn_mod := emqx_ws_connection}, ConnInfo = ConnInfo0#{conn_mod := ConnMod},
{Pid, Ref} = spawn_monitor(fun() -> receive stop -> exit(normal) end end), {Pid, Ref} = spawn_monitor(fun() -> receive stop -> exit(normal) end end),
ok = emqx_cm:register_channel(ClientId, Pid, ConnInfo), ok = emqx_cm:register_channel(ClientId, Pid, ConnInfo),
Pid ! stop, Pid ! stop,
receive {'DOWN', Ref, process, Pid, normal} -> ok end, receive {'DOWN', Ref, process, Pid, normal} -> ok end,
ok = emqx_cm:discard_session(ClientId), %% Here we simulate the situation where we are going to emqx_cm:discard_session/1
{ok, _} = ?block_until(#{?snk_kind := "session_already_gone", pid := Pid}, 1000) %% but the session has died.
emqx_cm:request_stepdown(discard, ConnMod, Pid),
{ok, _} = ?block_until(#{?snk_kind := "session_already_gone", stale_pid := Pid}, 2000)
end, end,
fun(_, _) -> fun(_, _) ->
true true