test(emqx_mgmt_cli): test that replicants do not join a left core node

This commit is contained in:
Serge Tupchii 2024-04-09 19:06:13 +03:00
parent 55179ccfed
commit fae9005f87
1 changed files with 19 additions and 19 deletions

View File

@ -33,12 +33,12 @@ end_per_suite(_) ->
emqx_mgmt_api_test_util:end_suite([emqx_management, emqx_conf]). emqx_mgmt_api_test_util:end_suite([emqx_management, emqx_conf]).
init_per_testcase(t_autocluster_leave = TC, Config) -> init_per_testcase(t_autocluster_leave = TC, Config) ->
[Core1, Core2, Core3, Repl] = [Core1, Core2, Repl1, Repl2] =
Nodes = [ Nodes = [
t_autocluster_leave_core1, t_autocluster_leave_core1,
t_autocluster_leave_core2, t_autocluster_leave_core2,
t_autocluster_leave_core3, t_autocluster_leave_replicant1,
t_autocluster_leave_replicant t_autocluster_leave_replicant2
], ],
NodeNames = [emqx_cth_cluster:node_name(N) || N <- Nodes], NodeNames = [emqx_cth_cluster:node_name(N) || N <- Nodes],
@ -58,8 +58,8 @@ init_per_testcase(t_autocluster_leave = TC, Config) ->
[ [
{Core1, #{role => core, apps => AppSpec}}, {Core1, #{role => core, apps => AppSpec}},
{Core2, #{role => core, apps => AppSpec}}, {Core2, #{role => core, apps => AppSpec}},
{Core3, #{role => core, apps => AppSpec}}, {Repl1, #{role => replicant, apps => AppSpec}},
{Repl, #{role => replicant, apps => AppSpec}} {Repl2, #{role => replicant, apps => AppSpec}}
], ],
#{work_dir => emqx_cth_suite:work_dir(TC, Config)} #{work_dir => emqx_cth_suite:work_dir(TC, Config)}
), ),
@ -307,7 +307,7 @@ t_admin(_Config) ->
ok. ok.
t_autocluster_leave(Config) -> t_autocluster_leave(Config) ->
[Core1, Core2, Core3, Repl] = Cluster = ?config(cluster, Config), [Core1, Core2, Repl1, Repl2] = Cluster = ?config(cluster, Config),
%% Mria membership updates are async, makes sense to wait a little %% Mria membership updates are async, makes sense to wait a little
timer:sleep(300), timer:sleep(300),
ClusterView = [lists:sort(rpc:call(N, emqx, running_nodes, [])) || N <- Cluster], ClusterView = [lists:sort(rpc:call(N, emqx, running_nodes, [])) || N <- Cluster],
@ -317,24 +317,24 @@ t_autocluster_leave(Config) ->
?assertEqual(View1, View3), ?assertEqual(View1, View3),
?assertEqual(View1, View4), ?assertEqual(View1, View4),
rpc:call(Core3, emqx_mgmt_cli, cluster, [["leave"]]), rpc:call(Core2, emqx_mgmt_cli, cluster, [["leave"]]),
timer:sleep(1000), timer:sleep(1000),
%% Replicant node may still discover and join Core3 which is now split from [Core1, Core2], %% Replicant nodes can discover Core2 which is now split from [Core1, Core2],
%% but it's expected to choose a bigger cluster of [Core1, Core2].. %% but they are expected to ignore Core2,
?assertMatch([Core3], rpc:call(Core3, emqx, running_nodes, [])), %% since mria_lb must filter out core nodes that disabled discovery.
?assertMatch([Core2], rpc:call(Core2, emqx, running_nodes, [])),
?assertEqual(undefined, rpc:call(Core1, erlang, whereis, [ekka_autocluster])), ?assertEqual(undefined, rpc:call(Core1, erlang, whereis, [ekka_autocluster])),
?assertEqual(lists:sort([Core1, Core2, Repl]), rpc:call(Core1, emqx, running_nodes, [])), ?assertEqual(lists:sort([Core1, Repl1, Repl2]), rpc:call(Core1, emqx, running_nodes, [])),
?assertEqual(lists:sort([Core1, Core2, Repl]), rpc:call(Core2, emqx, running_nodes, [])), ?assertEqual(lists:sort([Core1, Repl1, Repl2]), rpc:call(Repl1, emqx, running_nodes, [])),
?assertEqual(lists:sort([Core1, Core2, Repl]), rpc:call(Repl, emqx, running_nodes, [])), ?assertEqual(lists:sort([Core1, Repl1, Repl2]), rpc:call(Repl2, emqx, running_nodes, [])),
rpc:call(Repl, emqx_mgmt_cli, cluster, [["leave"]]), rpc:call(Repl1, emqx_mgmt_cli, cluster, [["leave"]]),
timer:sleep(1000), timer:sleep(1000),
?assertEqual(lists:sort([Core1, Core2]), rpc:call(Core1, emqx, running_nodes, [])), ?assertEqual(lists:sort([Core1, Repl2]), rpc:call(Core1, emqx, running_nodes, [])),
?assertEqual(lists:sort([Core1, Core2]), rpc:call(Core2, emqx, running_nodes, [])),
rpc:call(Core3, emqx_mgmt_cli, cluster, [["discovery", "enable"]]), rpc:call(Core2, emqx_mgmt_cli, cluster, [["discovery", "enable"]]),
rpc:call(Repl, emqx_mgmt_cli, cluster, [["discovery", "enable"]]), rpc:call(Repl1, emqx_mgmt_cli, cluster, [["discovery", "enable"]]),
%% core nodes will join and restart asyncly, may need more time to re-cluster %% nodes will join and restart asyncly, may need more time to re-cluster
?assertEqual( ?assertEqual(
ok, ok,
emqx_common_test_helpers:wait_for( emqx_common_test_helpers:wait_for(