summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2017-08-18 21:02:55 +0000
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2017-08-19 15:34:52 +0000
commit13a865edcaa6959410747f805208a09781482e7b (patch)
treea00c7052b14887494a687413658d08e3bab09b87
parentbb79416b6ef536c1b64876d8c9fe5e596dd1320a (diff)
downloadrebar-13a865edcaa6959410747f805208a09781482e7b.tar.gz
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.
-rw-r--r--src/rebar_ct.erl12
1 files changed, 9 insertions, 3 deletions
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) ->