From 7ace5ad60525b03aadacb05cfd0674070704c935 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 9 Aug 2019 21:28:13 -0700 Subject: add configurable timeouts to nodetool --- priv/templates/nodetool | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/priv/templates/nodetool b/priv/templates/nodetool index 9e24f32..faf19e7 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -22,20 +22,32 @@ main(Args) -> halt(1) end, + Timeout = + case os:get_env("NODETOOL_TIMEOUT") of + false -> + 60000; + StrVal -> + try + list_to_integer(StrVal) + catch _:_ -> + 60000 + end + end, + case RestArgs of ["ping"] -> %% If we got this far, the node already responsed to a ping, so just dump %% a "pong" io:format("pong\n"); ["stop"] -> - io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]); + io:format("~p\n", [rpc:call(TargetNode, init, stop, [], Timeout)]); ["restart"] -> - io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]); + io:format("~p\n", [rpc:call(TargetNode, init, restart, [], Timeout)]); ["reboot"] -> - io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]); + io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], Timeout)]); ["rpc", Module, Function | RpcArgs] -> case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - [RpcArgs], 60000) of + [RpcArgs], Timeout) of ok -> ok; {badrpc, Reason} -> @@ -46,7 +58,7 @@ main(Args) -> end; ["rpcterms", Module, Function | ArgsAsString] -> case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - consult(lists:flatten(ArgsAsString)), 60000) of + consult(lists:flatten(ArgsAsString)), Timeout) of {badrpc, Reason} -> io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), halt(1); -- cgit v1.2.3 From e57ed905fc3dd6f81326a61ee18f1958933d4091 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Sat, 10 Aug 2019 09:58:44 -0700 Subject: fix typo; add test --- priv/templates/nodetool | 2 +- test/rlx_extended_bin_SUITE.erl | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/priv/templates/nodetool b/priv/templates/nodetool index faf19e7..f460962 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -23,7 +23,7 @@ main(Args) -> end, Timeout = - case os:get_env("NODETOOL_TIMEOUT") of + case os:getenv("NODETOOL_TIMEOUT") of false -> 60000; StrVal -> diff --git a/test/rlx_extended_bin_SUITE.erl b/test/rlx_extended_bin_SUITE.erl index 710d2c4..d17a375 100644 --- a/test/rlx_extended_bin_SUITE.erl +++ b/test/rlx_extended_bin_SUITE.erl @@ -40,6 +40,7 @@ restart/1, reboot/1, escript/1, + os_var_timeouts/1, remote_console/1, shortname_remote_console/1, replace_os_vars/1, replace_os_vars_sys_config_vm_args_src/1, @@ -392,6 +393,48 @@ escript(Config) -> {ok, Output} = sh(filename:join([OutputDir, "foo", "bin", "foo escript script.erl"])), ?assertEqual(ExpectedOutput, Output). +os_var_timeouts(Config) -> + LibDir1 = proplists:get_value(lib1, Config), + + rlx_test_utils:create_app(LibDir1, "goal_app", "0.0.1", [stdlib,kernel], []), + + ConfigFile = filename:join([LibDir1, "relx.config"]), + rlx_test_utils:write_config(ConfigFile, + [{release, {foo, "0.0.1"}, + [goal_app]}, + {lib_dirs, [filename:join(LibDir1, "*")]}, + {generate_start_script, true}, + {extended_start_script, true} + ]), + + OutputDir = filename:join([proplists:get_value(priv_dir, Config), + rlx_test_utils:create_random_name("relx-output")]), + + {ok, _State} = relx:do([{relname, foo}, + {relvsn, "0.0.1"}, + {goals, []}, + {lib_dirs, [LibDir1]}, + {log_level, 3}, + {output_dir, OutputDir}, + {config, ConfigFile}], ["release"]), + + ok = ec_file:write(filename:join([OutputDir, "foo", "script.erl"]), + [rlx_test_utils:escript_contents()]), + + %% now start/stop the release to make sure the extended script is working + {ok, _} = sh(filename:join([OutputDir, "foo", "bin", "foo start"])), + timer:sleep(?SLEEP_TIME), + ?assertEqual({ok, "ok"}, sh(filename:join([OutputDir, "foo", "bin", + "foo rpcterms timer sleep 2000."]))), + ?assertEqual({ok, "ok"}, sh(filename:join([OutputDir, "foo", "bin", + "foo rpcterms timer sleep 2000."]), + [{"NODETOOL_TIMEOUT", "5asdnkajef"}])), + {error,1,"RPC to " ++ _Rest} = sh(filename:join([OutputDir, "foo", "bin", + "foo rpcterms timer sleep 2000."]), + [{"NODETOOL_TIMEOUT", "500"}]). + + + remote_console(Config) -> LibDir1 = proplists:get_value(lib1, Config), -- cgit v1.2.3