Improve pseudo-unique ct_run node name Replacing crypto:rand_uniform(0, 10000) with rebar_rnd:uniform(10000) (which is either rand:uniform or random:uniform dependent on what otp version it runs on) fails in rebar_ct. One might assume it's because the old call requests a number >= 0 while the new call has no way to ask for anything but >= 1. However, the way the value is used doesn't rely on it to include 0, so the bug lies elsewhere. Actually, generating a random number to choose a pseudo-unique ct_run node name isn't a reliable method to avoid naming clashes.
I cannot reproduce it locally and also cannot see the actual error in the CI logs. Mirroring what rebar_eunit does and using a bigger rng range seems to be enough to avoid node name clashes on Travis-CI. Project: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/commit/13a865ed Tree: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/tree/13a865ed Diff: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/diff/13a865ed Branch: refs/heads/master Commit: 13a865edcaa6959410747f805208a09781482e7b Parents: bb79416 Author: Tuncer Ayaz <[email protected]> Authored: Fri Aug 18 21:02:55 2017 +0000 Committer: Tuncer Ayaz <[email protected]> Committed: Sat Aug 19 15:34:52 2017 +0000 ---------------------------------------------------------------------- src/rebar_ct.erl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-rebar/blob/13a865ed/src/rebar_ct.erl ---------------------------------------------------------------------- diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 7c0f9d9..892ae03 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -237,6 +237,7 @@ make_cmd(TestDir, RawLogDir, Config) -> CodeDirs = [io_lib:format("\"~s\"", [Dir]) || Dir <- [EbinDir|NonLibCodeDirs]], CodePathString = string:join(CodeDirs, " "), + _ = rebar_rnd:seed({55, seconds(), 7331}), Cmd = case get_ct_specs(Config, search_ct_specs_from(Cwd, TestDir, Config)) of undefined -> ?FMT("~s" @@ -285,13 +286,18 @@ search_ct_specs_from(Cwd, TestDir, Config) -> Cwd end. +seconds() -> + calendar:datetime_to_gregorian_seconds(calendar:universal_time()). + build_name(Config) -> %% generate a unique name for our test node, we want %% to make sure the odds of name clashing are low - Random = integer_to_list(rebar_rnd:uniform(10000)), + Secs = integer_to_list(seconds()), + Random = integer_to_list(rebar_rnd:uniform(1000000)), + PseudoUnique = Random ++ "N" ++ Secs, case rebar_config:get_local(Config, ct_use_short_names, false) of - true -> "-sname test" ++ Random; - false -> " -name test" ++ Random ++ "@" ++ net_adm:localhost() + true -> "-sname test" ++ PseudoUnique; + false -> " -name test" ++ PseudoUnique ++ "@" ++ net_adm:localhost() end. get_extra_params(Config) ->
