From b82189fb4da06b490a13a97b5e7558150ff92086 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 5 Dec 2023 16:44:33 -0300 Subject: [PATCH] test(cth_peer): use an exclusive current dir for each peer --- apps/emqx/test/emqx_cth_peer.erl | 33 ++++++++++++------- .../test/emqx_mgmt_api_plugins_SUITE.erl | 11 +++++-- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/apps/emqx/test/emqx_cth_peer.erl b/apps/emqx/test/emqx_cth_peer.erl index 8b1996cbd..9ada4c6ec 100644 --- a/apps/emqx/test/emqx_cth_peer.erl +++ b/apps/emqx/test/emqx_cth_peer.erl @@ -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), diff --git a/apps/emqx_management/test/emqx_mgmt_api_plugins_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_plugins_SUITE.erl index 4909f8ce8..96be99691 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_plugins_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_plugins_SUITE.erl @@ -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) ->