From dfa2a3ce25862720d48c5ff8b71fdf31989ea1dc Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 25 Jan 2015 23:43:56 +0100 Subject: Add pool suite to test transport_opt() pool_size With testcases that uses restrict_connections and pool_size config to establish multiple connections between two Diameter nodes, checking for the expected number of transport processes using diameter:service_info/2. --- lib/diameter/test/diameter_util.erl | 49 +++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index 92c72c84e7..e95cbfceb5 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2013. All Rights Reserved. +%% Copyright Ericsson AB 2010-2015. 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 @@ -29,7 +29,8 @@ run/1, fold/3, foldl/3, - scramble/1]). + scramble/1, + have_sctp/0]). %% diameter-specific -export([lport/2, @@ -183,6 +184,19 @@ s(Acc, L) -> {H, [T|Rest]} = lists:split(random:uniform(length(L)) - 1, L), s([T|Acc], H ++ Rest). +%% --------------------------------------------------------------------------- +%% have_sctp/0 + +have_sctp() -> + case gen_sctp:open() of + {ok, Sock} -> + gen_sctp:close(Sock), + true; + {error, E} when E == eprotonosupport; + E == esocktnosupport -> %% fail on any other reason + false + end. + %% --------------------------------------------------------------------------- %% eval/1 %% @@ -254,13 +268,12 @@ path(Config, Name) -> %% %% Lookup the port number of a tcp/sctp listening transport. -lport(M, {Node, Ref}) -> - rpc:call(Node, ?MODULE, lport, [M, Ref]); +lport(Prot, {Node, Ref}) -> + rpc:call(Node, ?MODULE, lport, [Prot, Ref]); lport(Prot, Ref) -> - Mod = tmod(Prot), [_] = diameter_reg:wait({'_', listener, {Ref, '_'}}), - [N || {listen, N, _} <- Mod:ports(Ref)]. + [N || M <- tmod(Prot), {listen, N, _} <- M:ports(Ref)]. %% --------------------------------------------------------------------------- %% listen/2-3 @@ -292,13 +305,17 @@ connect(Client, Prot, LRef, Opts) -> Ref = add_transport(Client, {connect, opts(Prot, PortNr) ++ Opts}), true = transport(Client, Ref), %% assert - ok = receive - {diameter_event, Client, {up, Ref, _, _, _}} -> ok - after 10000 -> - {Client, Prot, PortNr, process_info(self(), messages)} - end, + diameter_lib:for_n(fun(_) -> ok = up(Client, Ref, Prot, PortNr) end, + proplists:get_value(pool_size, Opts, 1)), Ref. +up(Client, Ref, Prot, PortNr) -> + receive + {diameter_event, Client, {up, Ref, _, _, _}} -> ok + after 10000 -> + {Client, Prot, PortNr, process_info(self(), messages)} + end. + transport(SvcName, Ref) -> [Ref] == [R || [{ref, R} | _] <- diameter:service_info(SvcName, transport), R == Ref]. @@ -327,13 +344,15 @@ add_transport(SvcName, T) -> Ref. tmod(tcp) -> - diameter_tcp; + [diameter_tcp]; tmod(sctp) -> - diameter_sctp. + [diameter_sctp]; +tmod(any) -> + [diameter_sctp, diameter_tcp]. opts(Prot, T) -> - [{transport_module, tmod(Prot)}, - {transport_config, [{ip, ?ADDR}, {port, 0} | opts(T)]}]. + [{transport_module, M} || M <- tmod(Prot)] + ++ [{transport_config, [{ip, ?ADDR}, {port, 0} | opts(T)]}]. opts(listen) -> [{accept, M} || M <- [{256,0,0,1}, ["256.0.0.1", ["^.+$"]]]]; -- cgit v1.2.3 From eae8ecd1fd2ba33b1c81d0c19605047e2f317eda Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 10 Feb 2015 08:44:35 +0100 Subject: Use new time api in test suites Where it's less important to do so, but it has to be done at some point since erlang:now/0 is deprecated. As in the parent commit, continue to use the old api if the new one is unavailable. --- lib/diameter/test/diameter_util.erl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index e95cbfceb5..c496876ee1 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -30,6 +30,9 @@ fold/3, foldl/3, scramble/1, + timestamp/0, + seed/0, + unique_string/0, have_sctp/0]). %% diameter-specific @@ -175,7 +178,7 @@ scramble(L) -> [[fun s/1, L]]). s(L) -> - random:seed(now()), + random:seed(seed()), s([], L). s(Acc, []) -> @@ -184,6 +187,31 @@ s(Acc, L) -> {H, [T|Rest]} = lists:split(random:uniform(length(L)) - 1, L), s([T|Acc], H ++ Rest). +%% --------------------------------------------------------------------------- +%% timestamp/0 + +timestamp() -> + diameter_lib:timestamp(diameter_lib:now()). + +%% --------------------------------------------------------------------------- +%% seed/0 + +seed() -> + {_,T} = diameter_lib:seed(), + T. + +%% --------------------------------------------------------------------------- +%% unique_string/0 + +unique_string() -> + us(diameter_lib:now()). + +us({M,S,U}) -> + tl(lists:append(["-" ++ integer_to_list(N) || N <- [M,S,U]])); + +us(MonoT) -> + integer_to_list(MonoT). + %% --------------------------------------------------------------------------- %% have_sctp/0 -- cgit v1.2.3 From 4676eb881c2619250b384e8e1ab60bc8ae5d58c3 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sat, 23 May 2015 16:16:51 +0200 Subject: Fix incorrect suite usage of OTP 18 monotonic time Value was used as strictly increasing when it's only non-decreasing, causing testcases to fail. --- lib/diameter/test/diameter_util.erl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index c496876ee1..df7d268429 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -204,13 +204,14 @@ seed() -> %% unique_string/0 unique_string() -> - us(diameter_lib:now()). - -us({M,S,U}) -> - tl(lists:append(["-" ++ integer_to_list(N) || N <- [M,S,U]])); - -us(MonoT) -> - integer_to_list(MonoT). + try erlang:unique_integer() of + N -> + integer_to_list(N) + catch + error: undef -> %% OTP < 18 + {M,S,U} = timestamp(), + tl(lists:append(["-" ++ integer_to_list(N) || N <- [M,S,U]])) + end. %% --------------------------------------------------------------------------- %% have_sctp/0 -- cgit v1.2.3 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/diameter/test/diameter_util.erl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index df7d268429..0df216b9d0 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -3,16 +3,17 @@ %% %% Copyright Ericsson AB 2010-2015. 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 -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at %% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% -- cgit v1.2.3 From aea4c4d4c3b4293ef401621bfd46b6ee5a87cf1b Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Fri, 19 Jun 2015 09:35:55 +0200 Subject: Increase send/receive buffers for testsuite SCTP listeners The defaults result in sporadic timeouts in the traffic suite after testing over SCTP was added in commit fadf753b. The behaviour looks to be specific to SLES 11, and is presumably the same resends/congestion that lead to the buffers being increased in the gen_sctp suite in commit 12febf13 (and commented in commit e931991f). The behaviour hasn't been seen on SLES 10. --- lib/diameter/test/diameter_util.erl | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index df7d268429..c9022b9c53 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -380,12 +380,26 @@ tmod(any) -> [diameter_sctp, diameter_tcp]. opts(Prot, T) -> - [{transport_module, M} || M <- tmod(Prot)] - ++ [{transport_config, [{ip, ?ADDR}, {port, 0} | opts(T)]}]. + lists:append([[{transport_module, M}, {transport_config, C}] + || M <- tmod(Prot), + C <- [cfg(M,T) ++ cfg(M) ++ cfg(T)]]). -opts(listen) -> +%% Listening SCTP socket need larger-than-default buffers to avoid +%% resends on some platforms (eg. SLES 11). +cfg(diameter_sctp, listen) -> + [{recbuf, 1 bsl 16}, {sndbuf, 1 bsl 16}]; + +cfg(_, _) -> + []. + +cfg(M) + when M == diameter_tcp; + M == diameter_sctp -> + [{ip, ?ADDR}, {port, 0}]; + +cfg(listen) -> [{accept, M} || M <- [{256,0,0,1}, ["256.0.0.1", ["^.+$"]]]]; -opts(PortNr) -> +cfg(PortNr) -> [{raddr, ?ADDR}, {rport, PortNr}]. %% --------------------------------------------------------------------------- -- cgit v1.2.3 From b409496fdb0eaa293a63f5c98c8f642aa8ce7aaa Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 21 Jun 2015 11:38:38 +0200 Subject: Fix connection timeouts in test transports Without a timeout, TCP/SCTP connect can take some time to fail, which resulted in failures in the pool suite after the parent commit fixed the previously faulty sctp-first-then-tcp connect. --- lib/diameter/test/diameter_util.erl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index c9022b9c53..5701ede0c1 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -380,9 +380,21 @@ tmod(any) -> [diameter_sctp, diameter_tcp]. opts(Prot, T) -> - lists:append([[{transport_module, M}, {transport_config, C}] - || M <- tmod(Prot), - C <- [cfg(M,T) ++ cfg(M) ++ cfg(T)]]). + tmo(T, lists:append([[{transport_module, M}, {transport_config, C}] + || M <- tmod(Prot), + C <- [cfg(M,T) ++ cfg(M) ++ cfg(T)]])). + +tmo(listen, Opts) -> + Opts; +tmo(_, Opts) -> + tmo(Opts). + +%% Timeout on all but the last alternative. +tmo([_,_] = Opts) -> + Opts; +tmo([M, C | Opts]) -> + {transport_config = K, Cfg} = C, + [M, {K, Cfg, 5000} | tmo(Opts)]. %% Listening SCTP socket need larger-than-default buffers to avoid %% resends on some platforms (eg. SLES 11). -- cgit v1.2.3 From 96d63dca845e18f86488db9d8dfb33eb76ad0467 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 4 Aug 2015 23:46:29 +0200 Subject: Simplify time manipulation By doing away with more wrapping that the parent commit started to remove. --- lib/diameter/test/diameter_util.erl | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index df7d268429..e8fab18a45 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -30,8 +30,6 @@ fold/3, foldl/3, scramble/1, - timestamp/0, - seed/0, unique_string/0, have_sctp/0]). @@ -178,7 +176,7 @@ scramble(L) -> [[fun s/1, L]]). s(L) -> - random:seed(seed()), + random:seed(now()), s([], L). s(Acc, []) -> @@ -187,19 +185,6 @@ s(Acc, L) -> {H, [T|Rest]} = lists:split(random:uniform(length(L)) - 1, L), s([T|Acc], H ++ Rest). -%% --------------------------------------------------------------------------- -%% timestamp/0 - -timestamp() -> - diameter_lib:timestamp(diameter_lib:now()). - -%% --------------------------------------------------------------------------- -%% seed/0 - -seed() -> - {_,T} = diameter_lib:seed(), - T. - %% --------------------------------------------------------------------------- %% unique_string/0 @@ -209,7 +194,7 @@ unique_string() -> integer_to_list(N) catch error: undef -> %% OTP < 18 - {M,S,U} = timestamp(), + {M,S,U} = now(), tl(lists:append(["-" ++ integer_to_list(N) || N <- [M,S,U]])) end. -- cgit v1.2.3 From 80dc4f14b21cf316a8000f91cd77b1f0653afa7c Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Tue, 24 May 2016 14:58:50 +0200 Subject: Fix leaking transports in traffic/relay suites Listening transports weren't removed, which diameter_reg:subs/0 revealed. --- lib/diameter/test/diameter_util.erl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index 52b747e99c..f26f1e999a 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -345,11 +345,12 @@ transport(SvcName, Ref) -> disconnect(Client, Ref, Server, LRef) -> true = diameter:subscribe(Server), ok = diameter:remove_transport(Client, Ref), - ok = receive - {diameter_event, Server, {down, LRef, _, _}} -> ok - after 10000 -> - {Client, Ref, Server, LRef, process_info(self(), messages)} - end. + receive + {diameter_event, Server, {down, LRef, _, _}} -> + ok + after 10000 -> + {Client, Ref, Server, LRef, process_info(self(), messages)} + end. %% --------------------------------------------------------------------------- -- cgit v1.2.3 From c980e489d02417e1144d28958fe9abd4017f72a4 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sat, 11 Jun 2016 12:42:43 +0200 Subject: Use rand(3) instead of random(3) The latter is deprecated in OTP 19. --- lib/diameter/test/diameter_util.erl | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'lib/diameter/test/diameter_util.erl') diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index f26f1e999a..37fcbbc267 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010-2015. All Rights Reserved. +%% Copyright Ericsson AB 2010-2016. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ fold/3, foldl/3, scramble/1, - seed/0, unique_string/0, have_sctp/0]). @@ -178,22 +177,14 @@ scramble(L) -> [[fun s/1, L]]). s(L) -> - random:seed(seed()), s([], L). s(Acc, []) -> Acc; s(Acc, L) -> - {H, [T|Rest]} = lists:split(random:uniform(length(L)) - 1, L), + {H, [T|Rest]} = lists:split(rand:uniform(length(L)) - 1, L), s([T|Acc], H ++ Rest). -%% --------------------------------------------------------------------------- -%% seed/0 - -seed() -> - {_,T} = diameter_lib:seed(), - T. - %% --------------------------------------------------------------------------- %% unique_string/0 -- cgit v1.2.3