summaryrefslogtreecommitdiff
path: root/src/gm_tests.erl
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2011-02-22 22:54:12 +0000
committerMatthew Sackman <matthew@rabbitmq.com>2011-02-22 22:54:12 +0000
commitc3f44f9a82132f63ad9b1566874c054909c6733f (patch)
tree989cf4bc9cb74e8eb07392317786ef588129e7cf /src/gm_tests.erl
parentfd53e724c289b17eca48aa2252376231be51eb41 (diff)
downloadrabbitmq-server-c3f44f9a82132f63ad9b1566874c054909c6733f.tar.gz
Magic macroification
Diffstat (limited to 'src/gm_tests.erl')
-rw-r--r--src/gm_tests.erl53
1 files changed, 21 insertions, 32 deletions
diff --git a/src/gm_tests.erl b/src/gm_tests.erl
index 38b3db2f..bb92bc4c 100644
--- a/src/gm_tests.erl
+++ b/src/gm_tests.erl
@@ -27,6 +27,14 @@
-include("gm_specs.hrl").
+-define(RECEIVE_AFTER(Body, Bool, Error),
+ receive Body ->
+ true = Bool,
+ passed
+ after 1000 ->
+ throw(Error)
+ end).
+
joined(Pid, Members) ->
Pid ! {joined, self(), Members},
ok.
@@ -123,43 +131,24 @@ with_two_members(Fun) ->
end.
receive_or_throw(Pattern, Error) ->
- receive Pattern ->
- passed
- after 1000 ->
- throw(Error)
- end.
+ ?RECEIVE_AFTER(Pattern, true, Error).
receive_birth(From, Born, Error) ->
- receive {members_changed, From, Birth, Death} ->
- [Born] = Birth,
- [] = Death,
- passed
- after 1000 ->
- throw(Error)
- end.
+ ?RECEIVE_AFTER({members_changed, From, Birth, Death},
+ ([Born] == Birth) andalso ([] == Death),
+ Error).
receive_death(From, Died, Error) ->
- receive {members_changed, From, Birth, Death} ->
- [] = Birth,
- [Died] = Death,
- passed
- after 1000 ->
- throw(Error)
- end.
+ ?RECEIVE_AFTER({members_changed, From, Birth, Death},
+ ([] == Birth) andalso ([Died] == Death),
+ Error).
receive_joined(From, Members, Error) ->
- Members1 = lists:usort(Members),
- receive {joined, From, Members2} ->
- Members1 = lists:usort(Members2),
- passed
- after 1000 ->
- throw(Error)
- end.
+ ?RECEIVE_AFTER({joined, From, Members2},
+ lists:usort(Members) == lists:usort(Members2),
+ Error).
receive_termination(From, Reason, Error) ->
- receive {termination, From, Reason1} ->
- Reason = Reason1,
- passed
- after 1000 ->
- throw(Error)
- end.
+ ?RECEIVE_AFTER({termination, From, Reason1},
+ Reason == Reason1,
+ Error).