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) ->
|
start_nodes_init(Specs, Timeout) ->
|
||||||
Names = lists:map(fun(#{name := Name}) -> Name end, Specs),
|
Names = lists:map(fun(#{name := Name}) -> Name end, Specs),
|
||||||
Nodes = start_bare_nodes(Names, Timeout),
|
_Nodes = start_bare_nodes(Names, Timeout),
|
||||||
lists:foreach(fun node_init/1, Nodes).
|
lists:foreach(fun node_init/1, Specs).
|
||||||
|
|
||||||
start_bare_nodes(Names) ->
|
start_bare_nodes(Names) ->
|
||||||
start_bare_nodes(Names, ?TIMEOUT_NODE_START_MS).
|
start_bare_nodes(Names, ?TIMEOUT_NODE_START_MS).
|
||||||
|
|
||||||
start_bare_nodes(Names, Timeout) ->
|
start_bare_nodes(Names, Timeout) ->
|
||||||
Args = erl_flags(),
|
Args = erl_flags(),
|
||||||
Envs = [],
|
Envs = [],
|
||||||
|
@ -355,7 +356,7 @@ start_bare_nodes(Names, Timeout) ->
|
||||||
Nodes.
|
Nodes.
|
||||||
|
|
||||||
deadline(Timeout) ->
|
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) ->
|
is_overdue(Deadline) ->
|
||||||
erlang:monotonic_time() > Deadline.
|
erlang:monotonic_time() > Deadline.
|
||||||
|
@ -379,10 +380,15 @@ wait_boot_complete(Waits, Deadline) ->
|
||||||
wait_boot_complete(Waits, Deadline)
|
wait_boot_complete(Waits, Deadline)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
node_init(Node) ->
|
node_init(#{name := Node, work_dir := WorkDir}) ->
|
||||||
% Make it possible to call `ct:pal` and friends (if running under rebar3)
|
%% 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),
|
_ = share_load_module(Node, cthr),
|
||||||
% Enable snabbkaffe trace forwarding
|
%% Enable snabbkaffe trace forwarding
|
||||||
ok = snabbkaffe:forward_trace(Node),
|
ok = snabbkaffe:forward_trace(Node),
|
||||||
when_cover_enabled(fun() -> {ok, _} = cover:start([Node]) end),
|
when_cover_enabled(fun() -> {ok, _} = cover:start([Node]) end),
|
||||||
ok.
|
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) ->
|
do_start(Name0, Args, Envs, Timeout, Func) when is_atom(Name0) ->
|
||||||
{Name, Host} = parse_node_name(Name0),
|
{Name, Host} = parse_node_name(Name0),
|
||||||
%% Create exclusive current directory for the node. Some configurations, like plugin
|
{ok, Pid, Node} = peer:Func(#{
|
||||||
%% installation directory, are the same for the whole cluster, and nodes on the same
|
name => Name,
|
||||||
%% machine will step on each other's toes...
|
host => Host,
|
||||||
{ok, Cwd} = file:get_cwd(),
|
args => Args,
|
||||||
NodeCwd = filename:join([Cwd, Name]),
|
env => Envs,
|
||||||
ok = filelib:ensure_dir(filename:join([NodeCwd, "dummy"])),
|
wait_boot => Timeout,
|
||||||
try
|
longnames => true,
|
||||||
file:set_cwd(NodeCwd),
|
shutdown => {halt, 1000}
|
||||||
{ok, Pid, Node} = peer:Func(#{
|
}),
|
||||||
name => Name,
|
true = register(Node, Pid),
|
||||||
host => Host,
|
{ok, Node}.
|
||||||
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) ->
|
stop(Node) when is_atom(Node) ->
|
||||||
Pid = whereis(Node),
|
Pid = whereis(Node),
|
||||||
|
|
Loading…
Reference in New Issue