feat(cth-cluster): use workdir as cwd on each node
This commit is contained in:
parent
d60ff1e616
commit
56eefe34d5
|
@ -332,11 +332,12 @@ allocate_listener_ports(Types, Spec) ->
|
|||
|
||||
start_nodes_init(Specs, Timeout) ->
|
||||
Names = lists:map(fun(#{name := Name}) -> Name end, Specs),
|
||||
Nodes = start_bare_nodes(Names, Timeout),
|
||||
lists:foreach(fun node_init/1, Nodes).
|
||||
_Nodes = start_bare_nodes(Names, Timeout),
|
||||
lists:foreach(fun node_init/1, Specs).
|
||||
|
||||
start_bare_nodes(Names) ->
|
||||
start_bare_nodes(Names, ?TIMEOUT_NODE_START_MS).
|
||||
|
||||
start_bare_nodes(Names, Timeout) ->
|
||||
Args = erl_flags(),
|
||||
Envs = [],
|
||||
|
@ -355,7 +356,7 @@ start_bare_nodes(Names, Timeout) ->
|
|||
Nodes.
|
||||
|
||||
deadline(Timeout) ->
|
||||
erlang:monotonic_time() + erlang:convert_time_unit(Timeout, millisecond, nanosecond).
|
||||
erlang:monotonic_time() + erlang:convert_time_unit(Timeout, millisecond, native).
|
||||
|
||||
is_overdue(Deadline) ->
|
||||
erlang:monotonic_time() > Deadline.
|
||||
|
@ -379,10 +380,15 @@ wait_boot_complete(Waits, Deadline) ->
|
|||
wait_boot_complete(Waits, Deadline)
|
||||
end.
|
||||
|
||||
node_init(Node) ->
|
||||
% Make it possible to call `ct:pal` and friends (if running under rebar3)
|
||||
node_init(#{name := Node, work_dir := WorkDir}) ->
|
||||
%% 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 = filelib:ensure_path(WorkDir),
|
||||
ok = erpc:call(Node, file, set_cwd, [WorkDir]),
|
||||
%% Make it possible to call `ct:pal` and friends (if running under rebar3)
|
||||
_ = share_load_module(Node, cthr),
|
||||
% Enable snabbkaffe trace forwarding
|
||||
%% Enable snabbkaffe trace forwarding
|
||||
ok = snabbkaffe:forward_trace(Node),
|
||||
when_cover_enabled(fun() -> {ok, _} = cover:start([Node]) end),
|
||||
ok.
|
||||
|
|
|
@ -43,28 +43,17 @@ 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),
|
||||
%% 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.
|
||||
{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}.
|
||||
|
||||
stop(Node) when is_atom(Node) ->
|
||||
Pid = whereis(Node),
|
||||
|
|
Loading…
Reference in New Issue