fix(ct): adapt cluster setup helper to replicant nodes

Before this change, trying to start cluster consisting of cores +
replicants resulted in error joining replicant node to the cluster.
This commit is contained in:
Andrew Mayorov 2023-06-14 22:14:28 +03:00
parent 52354bf58a
commit acd6e5635b
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
6 changed files with 30 additions and 22 deletions

View File

@ -652,10 +652,13 @@ ensure_quic_listener(Name, UdpPort, ExtraSettings) ->
%% Extras app starting handler. It is the second arg passed to emqx_common_test_helpers:start_apps/2 %% Extras app starting handler. It is the second arg passed to emqx_common_test_helpers:start_apps/2
env_handler => fun((AppName :: atom()) -> term()), env_handler => fun((AppName :: atom()) -> term()),
%% Application env preset before calling `emqx_common_test_helpers:start_apps/2` %% Application env preset before calling `emqx_common_test_helpers:start_apps/2`
env => {AppName :: atom(), Key :: atom(), Val :: term()}, env => [{AppName :: atom(), Key :: atom(), Val :: term()}],
%% Whether to execute `emqx_config:init_load(SchemaMod)` %% Whether to execute `emqx_config:init_load(SchemaMod)`
%% default: true %% default: true
load_schema => boolean(), load_schema => boolean(),
%% Which node in the cluster to join to.
%% default: first core node
join_to => node(),
%% If we want to exercise the scenario where a node joins an %% If we want to exercise the scenario where a node joins an
%% existing cluster where there has already been some %% existing cluster where there has already been some
%% configuration changes (via cluster rpc), then we need to enable %% configuration changes (via cluster rpc), then we need to enable
@ -690,28 +693,38 @@ emqx_cluster(Specs0, CommonOpts) ->
]), ]),
%% Set the default node of the cluster: %% Set the default node of the cluster:
CoreNodes = [node_name(Name) || {{core, Name, _}, _} <- Specs], CoreNodes = [node_name(Name) || {{core, Name, _}, _} <- Specs],
JoinTo0 = JoinTo =
case CoreNodes of case CoreNodes of
[First | _] -> First; [First | _] -> First;
_ -> undefined _ -> undefined
end, end,
JoinTo = NodeOpts = fun(Number) ->
case maps:find(join_to, CommonOpts) of #{
{ok, true} -> JoinTo0; base_port => base_port(Number),
{ok, JT} -> JT; env => [
error -> JoinTo0 {mria, core_nodes, CoreNodes},
end, {gen_rpc, client_config_per_node, {internal, GenRpcPorts}}
[ ]
{Name, }
merge_opts(Opts, #{ end,
base_port => base_port(Number), RoleOpts = fun
(core) ->
#{
join_to => JoinTo, join_to => JoinTo,
env => [ env => [
{mria, core_nodes, CoreNodes}, {mria, node_role, core}
{mria, node_role, Role},
{gen_rpc, client_config_per_node, {internal, GenRpcPorts}}
] ]
})} };
(replicant) ->
#{
env => [
{mria, node_role, replicant},
{ekka, cluster_discovery, {static, [{seeds, CoreNodes}]}}
]
}
end,
[
{Name, merge_opts(merge_opts(NodeOpts(Number), RoleOpts(Role)), Opts)}
|| {{Role, Name, Opts}, Number} <- Specs || {{Role, Name, Opts}, Number} <- Specs
]. ].

View File

@ -140,7 +140,7 @@ mk_cluster_specs(Config, Opts) ->
{core, emqx_bridge_api_SUITE1, #{}}, {core, emqx_bridge_api_SUITE1, #{}},
{core, emqx_bridge_api_SUITE2, #{}} {core, emqx_bridge_api_SUITE2, #{}}
], ],
CommonOpts = #{ CommonOpts = Opts#{
env => [{emqx, boot_modules, [broker]}], env => [{emqx, boot_modules, [broker]}],
apps => [], apps => [],
% NOTE % NOTE
@ -157,7 +157,6 @@ mk_cluster_specs(Config, Opts) ->
load_apps => ?SUITE_APPS ++ [emqx_dashboard], load_apps => ?SUITE_APPS ++ [emqx_dashboard],
env_handler => fun load_suite_config/1, env_handler => fun load_suite_config/1,
load_schema => false, load_schema => false,
join_to => maps:get(join_to, Opts, true),
priv_data_dir => ?config(priv_dir, Config) priv_data_dir => ?config(priv_dir, Config)
}, },
emqx_common_test_helpers:emqx_cluster(Specs, CommonOpts). emqx_common_test_helpers:emqx_cluster(Specs, CommonOpts).

View File

@ -247,7 +247,6 @@ cluster(Specs, Config) ->
{env, Env}, {env, Env},
{apps, [emqx_conf]}, {apps, [emqx_conf]},
{load_schema, false}, {load_schema, false},
{join_to, true},
{priv_data_dir, PrivDataDir}, {priv_data_dir, PrivDataDir},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->

View File

@ -284,7 +284,6 @@ cluster(Specs) ->
{env, Env}, {env, Env},
{apps, [emqx_conf]}, {apps, [emqx_conf]},
{load_schema, false}, {load_schema, false},
{join_to, true},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->
application:set_env(emqx, boot_modules, []), application:set_env(emqx, boot_modules, []),

View File

@ -159,7 +159,6 @@ cluster(Specs) ->
{env, Env}, {env, Env},
{apps, [emqx_conf, emqx_management]}, {apps, [emqx_conf, emqx_management]},
{load_schema, false}, {load_schema, false},
{join_to, true},
{env_handler, fun {env_handler, fun
(emqx) -> (emqx) ->
application:set_env(emqx, boot_modules, []), application:set_env(emqx, boot_modules, []),

View File

@ -444,7 +444,6 @@ cluster(Config) ->
env => [{mria, db_backend, rlog}], env => [{mria, db_backend, rlog}],
load_schema => true, load_schema => true,
start_autocluster => true, start_autocluster => true,
join_to => true,
listener_ports => [], listener_ports => [],
conf => [{[dashboard, listeners, http, bind], 0}], conf => [{[dashboard, listeners, http, bind], 0}],
env_handler => env_handler =>