aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/test/diameter_util.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2011-10-09 23:37:21 +0200
committerAnders Svensson <[email protected]>2011-10-10 11:27:07 +0200
commitbc099fc49937477d96f930237fc58d388a0d43ef (patch)
treedd2ba4d336fedd4e839339b173fef7da272f0bc9 /lib/diameter/test/diameter_util.erl
parent7de6f57074245a51faf1379629fe2000ae1037e5 (diff)
downloadotp-bc099fc49937477d96f930237fc58d388a0d43ef.tar.gz
otp-bc099fc49937477d96f930237fc58d388a0d43ef.tar.bz2
otp-bc099fc49937477d96f930237fc58d388a0d43ef.zip
Use util to simplify connection establishment in suites
Diffstat (limited to 'lib/diameter/test/diameter_util.erl')
-rw-r--r--lib/diameter/test/diameter_util.erl63
1 files changed, 28 insertions, 35 deletions
diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl
index 3574094417..3fe8ea5363 100644
--- a/lib/diameter/test/diameter_util.erl
+++ b/lib/diameter/test/diameter_util.erl
@@ -33,9 +33,9 @@
%% diameter-specific
-export([lport/2,
lport/3,
- service/1,
listen/2,
- connect/3]).
+ connect/3,
+ disconnect/4]).
%% common_test-specific
-export([write_priv/3,
@@ -254,27 +254,12 @@ lp(M, Ref, T) ->
end.
%% ---------------------------------------------------------------------------
-%% service/1
-%%
-%% Start a new diameter service and return its generated name.
-
-service(Opts) ->
- Name = make_ref(),
-
- case diameter:start_service(Name, Opts) of
- ok ->
- {ok, Name};
- {error, _} = No ->
- No
- end.
-
-%% ---------------------------------------------------------------------------
%% listen/2
%%
%% Add a listening transport on the loopback address and a free port.
listen(SvcName, Prot) ->
- add_transport(SvcName, {listen, transport(Prot, listen)}).
+ add_transport(SvcName, {listen, opts(Prot, listen)}).
%% ---------------------------------------------------------------------------
%% connect/3
@@ -282,15 +267,31 @@ listen(SvcName, Prot) ->
%% Add a connecting transport on and connect to a listening transport
%% with the specified reference.
-connect(SvcName, Prot, LRef) ->
- [PortNr] = lport(Prot, LRef),
- Ref = add_transport(SvcName, {connect, transport(Prot, PortNr)}),
- true = diameter:subscribe(SvcName),
- receive
- {diameter_event, SvcName, {up, Ref, _, _, _}} -> Ref
- after 2000 ->
- error({up, SvcName, Prot, PortNr})
- end.
+connect(Client, Prot, LRef) ->
+ [PortNr] = lport(Prot, LRef, 20),
+ Ref = add_transport(Client, {connect, opts(Prot, PortNr)}),
+ true = diameter:subscribe(Client),
+ ok = receive
+ {diameter_event, Client, {up, Ref, _, _, _}} -> ok
+ after 2000 ->
+ {Client, Prot, PortNr, process_info(self(), messages)}
+ end,
+ Ref.
+
+%% ---------------------------------------------------------------------------
+%% disconnect/4
+%%
+%% Remove the client transport and expect the server transport to go
+%% down.
+
+disconnect(Client, Ref, Server, LRef) ->
+ true = diameter:subscribe(Server),
+ ok = diameter:remove_transport(Client, Ref),
+ ok = receive
+ {diameter_event, Server, {down, LRef, _, _}} -> ok
+ after 2000 ->
+ {Client, Ref, Server, LRef, process_info(self(), messages)}
+ end.
%% ---------------------------------------------------------------------------
@@ -305,14 +306,6 @@ tmod(tcp) ->
tmod(sctp) ->
diameter_sctp.
-transport(Prot, T) ->
- {tag(T), opts(Prot, T)}.
-
-tag(listen = T) ->
- T;
-tag(_PortNr) ->
- connect.
-
opts(Prot, T) ->
[{transport_module, tmod(Prot)},
{transport_config, [{ip, ?ADDR}, {port, 0} | opts(T)]}].