test(cth_peer): use an exclusive current dir for each peer

This commit is contained in:
Thales Macedo Garitezi 2023-12-05 16:44:33 -03:00
parent 99399c6e95
commit b82189fb4d
2 changed files with 31 additions and 13 deletions

View File

@ -43,17 +43,28 @@ start_link(Name, Args, Envs, Timeout) when is_atom(Name) ->
do_start(Name0, Args, Envs, Timeout, Func) when is_atom(Name0) ->
{Name, Host} = parse_node_name(Name0),
{ok, Pid, Node} = peer:Func(#{
name => Name,
host => Host,
args => Args,
env => Envs,
wait_boot => Timeout,
longnames => true,
shutdown => {halt, 1000}
}),
true = register(Node, Pid),
{ok, Node}.
%% Create exclusive current directory for the node. Some configurations, like plugin
%% installation directory, are the same for the whole cluster, and nodes on the same
%% machine will step on each other's toes...
{ok, Cwd} = file:get_cwd(),
NodeCwd = filename:join([Cwd, Name]),
ok = filelib:ensure_dir(filename:join([NodeCwd, "dummy"])),
try
file:set_cwd(NodeCwd),
{ok, Pid, Node} = peer:Func(#{
name => Name,
host => Host,
args => Args,
env => Envs,
wait_boot => Timeout,
longnames => true,
shutdown => {halt, 1000}
}),
true = register(Node, Pid),
{ok, Node}
after
file:set_cwd(Cwd)
end.
stop(Node) when is_atom(Node) ->
Pid = whereis(Node),

View File

@ -27,6 +27,8 @@
-define(CLUSTER_API_SERVER(PORT), ("http://127.0.0.1:" ++ (integer_to_list(PORT)))).
-import(emqx_common_test_helpers, [on_exit/1]).
all() ->
emqx_common_test_helpers:all(?MODULE).
@ -66,8 +68,9 @@ init_per_testcase(_TestCase, Config) ->
end_per_testcase(t_cluster_update_order, Config) ->
Cluster = ?config(cluster, Config),
emqx_cth_cluster:stop(Cluster),
ok;
end_per_testcase(common, Config);
end_per_testcase(_TestCase, _Config) ->
emqx_common_test_helpers:call_janitor(),
ok.
t_plugins(Config) ->
@ -136,10 +139,14 @@ t_install_plugin_matching_exisiting_name(Config) ->
t_bad_plugin(Config) ->
DemoShDir = proplists:get_value(demo_sh_dir, Config),
PackagePathOrig = get_demo_plugin_package(DemoShDir),
BackupPath = filename:join(["/tmp", [filename:basename(PackagePathOrig), ".backup"]]),
{ok, _} = file:copy(PackagePathOrig, BackupPath),
on_exit(fun() -> {ok, _} = file:rename(BackupPath, PackagePathOrig) end),
PackagePath = filename:join([
filename:dirname(PackagePathOrig),
"bad_plugin-1.0.0.tar.gz"
]),
on_exit(fun() -> file:delete(PackagePath) end),
ct:pal("package_location:~p orig:~p", [PackagePath, PackagePathOrig]),
%% rename plugin tarball
file:copy(PackagePathOrig, PackagePath),
@ -358,7 +365,7 @@ cluster(TestCase, Config) ->
{Node1Name, #{role => core, apps => Node1Apps, join_to => Node1}},
{emqx_mgmt_api_plugins_SUITE2, #{role => core, apps => Node2Apps, join_to => Node1}}
],
#{work_dir => filename:join(?config(priv_dir, Config), TestCase)}
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
).
app_specs(_Config) ->