fix(cth): do not allocate ports for `emqx` app by default

This causes tricky and impressively hard to track side effects down
the line. Namely, loading `emqx_schema` _after_ `emqx_conf_schema`
(as part of cluster node startup sequence) leads to a couple of
schema root rewrites, because `emqx_schema` defines similar config
roots yet slightly differently (e.g. `authorization`).
This commit is contained in:
Andrew Mayorov 2023-09-01 17:23:34 +04:00
parent 0a879bffd1
commit 545f1c84a6
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
2 changed files with 35 additions and 22 deletions

View File

@ -237,8 +237,6 @@ default_appspec(emqx_conf, Spec, _NodeSpecs) ->
listeners => allocate_listener_ports([tcp, ssl, ws, wss], Spec)
}
};
default_appspec(emqx, Spec, _NodeSpecs) ->
#{config => #{listeners => allocate_listener_ports([tcp, ssl, ws, wss], Spec)}};
default_appspec(_App, _, _) ->
#{}.

View File

@ -38,23 +38,10 @@ groups() ->
init_per_group(GroupName, Config) ->
WorkDir = filename:join([?config(priv_dir, Config), ?MODULE, GroupName]),
NodeSpec = #{
apps => [
{emqx, #{
config => mk_config(GroupName),
after_start => fun() ->
% NOTE
% This one is actually defined on `emqx_conf_schema` level, but used
% in `emqx_broker`. Thus we have to resort to this ugly hack.
emqx_config:force_put([rpc, mode], async)
end
}}
]
},
NodeSpecs = [
{emqx_routing_SUITE1, NodeSpec#{role => core}},
{emqx_routing_SUITE2, NodeSpec#{role => core}},
{emqx_routing_SUITE3, NodeSpec#{role => replicant}}
{emqx_routing_SUITE1, #{apps => mk_appspecs(GroupName, 1), role => core}},
{emqx_routing_SUITE2, #{apps => mk_appspecs(GroupName, 2), role => core}},
{emqx_routing_SUITE3, #{apps => mk_appspecs(GroupName, 3), role => replicant}}
],
Nodes = emqx_cth_cluster:start(NodeSpecs, #{work_dir => WorkDir}),
[{cluster, Nodes}, Config].
@ -62,10 +49,38 @@ init_per_group(GroupName, Config) ->
end_per_group(_GroupName, Config) ->
emqx_cth_cluster:stop(?config(cluster, Config)).
mk_config(routing_schema_v1) ->
"broker.routing.storage_schema = v1";
mk_config(routing_schema_v2) ->
"broker.routing.storage_schema = v2".
mk_appspecs(GroupName, N) ->
[
{emqx, #{
config => mk_config(GroupName, N),
after_start => fun() ->
% NOTE
% This one is actually defined on `emqx_conf_schema` level, but used
% in `emqx_broker`. Thus we have to resort to this ugly hack.
emqx_config:force_put([rpc, mode], async)
end
}}
].
mk_config(GroupName, N) ->
#{
broker => mk_config_broker(GroupName),
listeners => mk_config_listeners(N)
}.
mk_config_broker(routing_schema_v1) ->
#{routing => #{storage_schema => v1}};
mk_config_broker(routing_schema_v2) ->
#{routing => #{storage_schema => v2}}.
mk_config_listeners(N) ->
Port = 1883 + N,
#{
tcp => #{default => #{bind => "127.0.0.1:" ++ integer_to_list(Port)}},
ssl => #{default => #{enable => false}},
ws => #{default => #{enable => false}},
wss => #{default => #{enable => false}}
}.
t_cluster_routing(Config) ->
Cluster = ?config(cluster, Config),