summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2014-01-30 06:55:43 +0000
committerTim Watson <tim@rabbitmq.com>2014-01-30 06:55:43 +0000
commit289ad50c1cbd2a42a49883f00a99eed0662aaa34 (patch)
tree58121834b28e7d29d2c8235240bdae8b45b8568d
parent0d50f68d5bf4956f1ff769080955707a5b6b056e (diff)
downloadrabbitmq-server-git-289ad50c1cbd2a42a49883f00a99eed0662aaa34.tar.gz
Refactor the tests just a little bit more
Extract a helper to wait for process exits we're expecting. We ignore the potential race (when establishing the monitor) since the exit reason is irrelevant here, we just want to know the process is gone. Instead of hitting 'nonode@nohost', which is slow (perhaps due to DNS querying), we pull the current hostname and combine 'nonode' with that.
-rw-r--r--src/rabbit_tests.erl46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index f4b8763b89..8c60e9e334 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -1354,13 +1354,8 @@ test_mcall() ->
global:register_name(gfoo, P1),
P2 = spawn(fun() -> exit(bang) end),
-
- %% ensure P2 is dead before we continue
- MRef = erlang:monitor(process, P2),
- receive
- {'DOWN', MRef, _, _, _} -> ok
- end,
-
+ %% ensure P2 is dead (ignore the race setting up the monitor)
+ await_exit(P2),
P3 = spawn(fun gs2_test_crasher/0),
@@ -1371,6 +1366,9 @@ test_mcall() ->
register(bog, spawn(fun gs2_test_crasher/0)),
global:register_name(gbaz, spawn(fun gs2_test_crasher/0)),
+ {ok, Hostname} = inet:gethostname(),
+ NoNode = list_to_atom("nonode@" ++ Hostname),
+
Targets =
%% pids
[P1, P2, P3]
@@ -1379,7 +1377,7 @@ test_mcall() ->
[foo, bar, baz]
++
%% {Name, Node} pairs
- [{foo, node()}, {bar, node()}, {bog, node()}, {foo, nonode@nohost}]
+ [{foo, node()}, {bar, node()}, {bog, node()}, {foo, NoNode}]
++
%% {global, Name}
[{global, gfoo}, {global, gbar}, {global, gbaz}],
@@ -1388,29 +1386,31 @@ test_mcall() ->
{foo, node()},
{global, gfoo}]],
- BadResults = [{P2, noproc}, % died before use
- {P3, boom}, % died on first use
- {bar, noproc}, % never registered
- {baz, boom}, % died on first use
- {{bar, node()}, noproc}, % never registered
- {{bog, node()}, boom}, % died on first use
- {{foo, nonode@nohost}, nodedown}, % invalid node
- {{global, gbar}, noproc}, % never registered globally
- {{global, gbaz}, boom}], % died on first use
+ BadResults = [{P2, noproc}, % died before use
+ {P3, boom}, % died on first use
+ {bar, noproc}, % never registered
+ {baz, boom}, % died on first use
+ {{bar, node()}, noproc}, % never registered
+ {{bog, node()}, boom}, % died on first use
+ {{foo, NoNode}, nodedown}, % invalid node
+ {{global, gbar}, noproc}, % never registered globally
+ {{global, gbaz}, boom}], % died on first use
{Replies, Errors} = gen_server2:mcall([{T, hello} || T <- Targets]),
true = lists:sort(Replies) == lists:sort(GoodResults),
true = lists:sort(Errors) == lists:sort(BadResults),
- %% cleanup
+ %% cleanup (ignore the race setting up the monitor)
P1 ! stop,
- MRef1 = erlang:monitor(process, P1),
- receive
- {'DOWN', MRef1, _, _, _} -> ok
- end,
-
+ await_exit(P1),
passed.
+await_exit(Pid) ->
+ MRef = erlang:monitor(process, Pid),
+ receive
+ {'DOWN', MRef, _, _, _} -> ok
+ end.
+
gs2_test_crasher() ->
receive
{'$gen_call', _From, hello} -> exit(boom)