aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/test/diameter_transport_SUITE.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2013-04-07 18:52:07 +0200
committerAnders Svensson <[email protected]>2013-04-11 16:18:57 +0200
commite4d6772ceb4653756bca7ff684e75cab6bfd44ab (patch)
tree889e3014ebf700fef750c5d10849d6a8d3156293 /lib/diameter/test/diameter_transport_SUITE.erl
parent3c14f79079d6cb7bc7057c38eab39c0485b4c1c8 (diff)
downloadotp-e4d6772ceb4653756bca7ff684e75cab6bfd44ab.tar.gz
otp-e4d6772ceb4653756bca7ff684e75cab6bfd44ab.tar.bz2
otp-e4d6772ceb4653756bca7ff684e75cab6bfd44ab.zip
More robust listening port lookup in test suites
In particular, remove timing dependence by using diameter_reg:wait/1 to wait on the term registered by diameter_{tcp,sctp} when opening a listening socket.
Diffstat (limited to 'lib/diameter/test/diameter_transport_SUITE.erl')
-rw-r--r--lib/diameter/test/diameter_transport_SUITE.erl28
1 files changed, 5 insertions, 23 deletions
diff --git a/lib/diameter/test/diameter_transport_SUITE.erl b/lib/diameter/test/diameter_transport_SUITE.erl
index 893b7ba2f9..3121fe1957 100644
--- a/lib/diameter/test/diameter_transport_SUITE.erl
+++ b/lib/diameter/test/diameter_transport_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -54,9 +54,6 @@
-define(RECV(Pat, Ret), receive Pat -> Ret end).
-define(RECV(Pat), ?RECV(Pat, now())).
-%% Or not.
--define(WAIT(Ms), receive after Ms -> now() end).
-
%% Sockets are opened on the loopback address.
-define(ADDR, {127,0,0,1}).
@@ -209,7 +206,7 @@ init(accept, {Prot, Ref}) ->
init(gen_connect, {Prot, Ref}) ->
%% Lookup the peer's listening socket.
- [PortNr] = ?util:lport(Prot, Ref, 20),
+ [PortNr] = ?util:lport(Prot, Ref),
%% Connect, send a message and receive it back.
{ok, Sock} = gen_connect(Prot, PortNr),
@@ -230,7 +227,8 @@ init(gen_accept, {Prot, Ref}) ->
init(connect, {Prot, Ref}) ->
%% Lookup the peer's listening socket.
- [{?TEST_LISTENER(_, PortNr), _}] = match(?TEST_LISTENER(Ref, '_')),
+ [{?TEST_LISTENER(_, PortNr), _}]
+ = diameter_reg:wait(?TEST_LISTENER(Ref, '_')),
%% Start a connecting transport and receive notification of
%% the connection.
@@ -246,18 +244,6 @@ init(connect, {Prot, Ref}) ->
MRef = erlang:monitor(process, TPid),
?RECV({'DOWN', MRef, process, _, _}).
-match(Pat) ->
- match(Pat, 20).
-
-match(Pat, T) ->
- L = diameter_reg:match(Pat),
- if [] /= L orelse 1 == T ->
- L;
- true ->
- ?WAIT(50),
- match(Pat, T-1)
- end.
-
bin(sctp, #diameter_packet{bin = Bin}) ->
Bin;
bin(tcp, Bin) ->
@@ -316,16 +302,12 @@ start_connect(tcp, T, Svc, Opts) ->
start_accept(Prot, Ref) ->
Pid = sync(accept, Ref),
-
- %% Configure the same port number for transports on the same
- %% reference.
- [PortNr | _] = ?util:lport(Prot, Ref) ++ [0],
{Mod, Opts} = tmod(Prot),
try
{ok, TPid, [?ADDR]} = Mod:start({accept, Ref},
?SVC([?ADDR]),
- [{port, PortNr} | Opts]),
+ [{port, 0} | Opts]),
?RECV(?TMSG({TPid, connected})),
TPid
after