test(cm): cover {takeover, 'begin'/'end'} action
This commit is contained in:
parent
6dd0b49dd2
commit
66807f17df
|
@ -187,46 +187,78 @@ t_open_session_race_condition(_) ->
|
||||||
ok = flush_emqx_pool(),
|
ok = flush_emqx_pool(),
|
||||||
?assertEqual([], emqx_cm:lookup_channels(ClientId)).
|
?assertEqual([], emqx_cm:lookup_channels(ClientId)).
|
||||||
|
|
||||||
t_kick_session_discard_normal(_) ->
|
t_call_session_discard_normal(_) ->
|
||||||
test_kick_session(discard, normal).
|
test_call_session(discard, normal).
|
||||||
|
|
||||||
t_kick_session_discard_shutdown(_) ->
|
t_call_session_discard_shutdown(_) ->
|
||||||
test_kick_session(discard, shutdown).
|
test_call_session(discard, shutdown).
|
||||||
|
|
||||||
t_kick_session_discard_shutdown_with_reason(_) ->
|
t_call_session_discard_shutdown_with_reason(_) ->
|
||||||
test_kick_session(discard, {shutdown, discard}).
|
test_call_session(discard, {shutdown, discard}).
|
||||||
|
|
||||||
t_kick_session_discard_timeout(_) ->
|
t_call_session_discard_timeout(_) ->
|
||||||
test_kick_session(discard, timeout).
|
test_call_session(discard, timeout).
|
||||||
|
|
||||||
t_kick_session_discard_noproc(_) ->
|
t_call_session_discard_noproc(_) ->
|
||||||
test_kick_session(discard, noproc).
|
test_call_session(discard, noproc).
|
||||||
|
|
||||||
t_kick_session_kick_normal(_) ->
|
t_call_session_kick_normal(_) ->
|
||||||
test_kick_session(discard, normal).
|
test_call_session(kick, normal).
|
||||||
|
|
||||||
t_kick_session_kick_shutdown(_) ->
|
t_call_session_kick_shutdown(_) ->
|
||||||
test_kick_session(discard, shutdown).
|
test_call_session(kick, shutdown).
|
||||||
|
|
||||||
t_kick_session_kick_shutdown_with_reason(_) ->
|
t_call_session_kick_shutdown_with_reason(_) ->
|
||||||
test_kick_session(discard, {shutdown, discard}).
|
test_call_session(kick, {shutdown, discard}).
|
||||||
|
|
||||||
t_kick_session_kick_timeout(_) ->
|
t_call_session_kick_timeout(_) ->
|
||||||
test_kick_session(discard, timeout).
|
test_call_session(kick, timeout).
|
||||||
|
|
||||||
t_kick_session_kick_noproc(_) ->
|
t_call_session_kick_noproc(_) ->
|
||||||
test_kick_session(discard, noproc).
|
test_call_session(discard, noproc).
|
||||||
|
|
||||||
test_kick_session(Action, Reason) ->
|
t_call_session_takeover_begin_normal(_) ->
|
||||||
|
test_call_session({takeover, 'begin'}, normal).
|
||||||
|
|
||||||
|
t_call_session_takeover_begin_shutdown(_) ->
|
||||||
|
test_call_session({takeover, 'begin'}, shutdown).
|
||||||
|
|
||||||
|
t_call_session_takeover_begin_shutdown_with_reason(_) ->
|
||||||
|
test_call_session({takeover, 'begin'}, {shutdown, discard}).
|
||||||
|
|
||||||
|
t_call_session_takeover_begin_timeout(_) ->
|
||||||
|
test_call_session({takeover, 'begin'}, timeout).
|
||||||
|
|
||||||
|
t_call_session_takeover_begin_noproc(_) ->
|
||||||
|
test_call_session({takeover, 'begin'}, noproc).
|
||||||
|
|
||||||
|
t_call_session_takeover_end_normal(_) ->
|
||||||
|
test_call_session({takeover, 'end'}, normal).
|
||||||
|
|
||||||
|
t_call_session_takeover_end_shutdown(_) ->
|
||||||
|
test_call_session({takeover, 'end'}, shutdown).
|
||||||
|
|
||||||
|
t_call_session_takeover_end_shutdown_with_reason(_) ->
|
||||||
|
test_call_session({takeover, 'end'}, {shutdown, discard}).
|
||||||
|
|
||||||
|
t_call_session_takeover_end_timeout(_) ->
|
||||||
|
test_call_session({takeover, 'end'}, timeout).
|
||||||
|
|
||||||
|
t_call_session_takeover_end_noproc(_) ->
|
||||||
|
test_call_session({takeover, 'end'}, noproc).
|
||||||
|
|
||||||
|
test_call_session(Action, Reason) ->
|
||||||
ClientId = rand_client_id(),
|
ClientId = rand_client_id(),
|
||||||
#{conninfo := ConnInfo} = ?ChanInfo,
|
#{conninfo := ConnInfo} = ?ChanInfo,
|
||||||
FakeSessionFun =
|
FakeSessionFun =
|
||||||
fun Loop() ->
|
fun Loop() ->
|
||||||
receive
|
receive
|
||||||
{'$gen_call', From, A} when A =:= kick orelse
|
{'$gen_call', From, A} when A =:= kick orelse
|
||||||
A =:= discard ->
|
A =:= discard orelse
|
||||||
|
A =:= {takeover, 'begin'} orelse
|
||||||
|
A =:= {takeover, 'end'} ->
|
||||||
case Reason of
|
case Reason of
|
||||||
normal ->
|
normal when A =:= kick orelse A =:= discard ->
|
||||||
gen_server:reply(From, ok);
|
gen_server:reply(From, ok);
|
||||||
timeout ->
|
timeout ->
|
||||||
%% no response to the call
|
%% no response to the call
|
||||||
|
@ -249,9 +281,10 @@ test_kick_session(Action, Reason) ->
|
||||||
noproc -> exit(Pid1, kill), exit(Pid2, kill);
|
noproc -> exit(Pid1, kill), exit(Pid2, kill);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end,
|
end,
|
||||||
ok = case Action of
|
_ = case Action of
|
||||||
kick -> emqx_cm:kick_session(ClientId);
|
kick -> emqx_cm:kick_session(ClientId);
|
||||||
discard -> emqx_cm:discard_session(ClientId)
|
discard -> emqx_cm:discard_session(ClientId);
|
||||||
|
{takeover, _} -> emqx_cm:takeover_session(ClientId)
|
||||||
end,
|
end,
|
||||||
case Reason =:= timeout orelse Reason =:= noproc of
|
case Reason =:= timeout orelse Reason =:= noproc of
|
||||||
true ->
|
true ->
|
||||||
|
|
Loading…
Reference in New Issue