From 1132117b38cfe33e770a0d5b1a782d48667427c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Thu, 5 Mar 2015 13:37:16 +0100 Subject: Use new time API and be back-compatible in inets Remove unused functions and removed redundant test --- lib/inets/test/httpc_SUITE.erl | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'lib/inets/test/httpc_SUITE.erl') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index c535d59b9f..495d129661 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -1876,12 +1876,19 @@ run_clients(NumClients, ServerPort, SeqNumServer) -> wait4clients([], _Timeout) -> ok; wait4clients(Clients, Timeout) when Timeout > 0 -> - Time = now_ms(), + %% Adapt to OTP 18 erlang time API and be back-compatible + Time = try + erlang:monotonic_time() + catch + error:undef -> + %% Use Erlang system time as monotonic time + erlang:now() + end, receive {'DOWN', _MRef, process, Pid, normal} -> {value, {Id, _, _}} = lists:keysearch(Pid, 2, Clients), NewClients = lists:keydelete(Id, 1, Clients), - wait4clients(NewClients, Timeout - (now_ms() - Time)); + wait4clients(NewClients, Timeout - millisec_passed(Time)); {'DOWN', _MRef, process, Pid, Reason} -> {value, {Id, _, _}} = lists:keysearch(Pid, 2, Clients), ct:fail({bad_client_termination, Id, Reason}) @@ -1974,14 +1981,27 @@ parse_connection_type(Request) -> "keep-alive" -> keep_alive end. -%% Time in milli seconds -now_ms() -> - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000). +%% Help function, elapsed milliseconds since T0 +millisec_passed({_,_,_} = T0 ) -> + %% OTP 17 and earlier + timer:now_diff(erlang:now(), T0) div 1000; + +millisec_passed(T0) -> + %% OTP 18 + erlang:convert_time_resolution(erlang:monotonic_time() - T0, + erlang:time_resolution(), + 1000000) div 1000. set_random_seed() -> - {_, _, Micros} = now(), - A = erlang:phash2([make_ref(), self(), Micros]), + %% Adapt to OTP 18 erlang time API and be back-compatible + Unique = try + erlang:unique_integer() + catch + error:undef -> + {MS, S, US} = erlang:now(), + (MS*1000000+S)*1000000+US + end, + A = erlang:phash2([make_ref(), self(), Unique]), random:seed(A, A, A). -- cgit v1.2.3 From f4a774425a440caa912da71cfb8c0c70df4df69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Mon, 9 Mar 2015 11:16:01 +0100 Subject: Suppress deprecated warning on erlang:now/0 --- lib/inets/test/httpc_SUITE.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/inets/test/httpc_SUITE.erl') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 495d129661..6569027553 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -30,6 +30,7 @@ -include("http_internal.hrl"). %% Note: This directive should only be used in test suites. -compile(export_all). +-compile([{nowarn_deprecated_function,{erlang,now,0}}]). -define(URL_START, "http://"). -define(TLS_URL_START, "https://"). -- cgit v1.2.3 From 87ae700c7383b74b8ddade6bfe30481dcdc5b6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Fri, 13 Mar 2015 10:12:57 +0100 Subject: inets: Update comments --- lib/inets/test/httpc_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/inets/test/httpc_SUITE.erl') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 6569027553..348c75f787 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -1877,7 +1877,7 @@ run_clients(NumClients, ServerPort, SeqNumServer) -> wait4clients([], _Timeout) -> ok; wait4clients(Clients, Timeout) when Timeout > 0 -> - %% Adapt to OTP 18 erlang time API and be back-compatible + %% Adapt to OTP 18 erlang time API and be backwards compatible Time = try erlang:monotonic_time() catch @@ -1994,7 +1994,7 @@ millisec_passed(T0) -> 1000000) div 1000. set_random_seed() -> - %% Adapt to OTP 18 erlang time API and be back-compatible + %% Adapt to OTP 18 erlang time API and be backwards compatible Unique = try erlang:unique_integer() catch -- cgit v1.2.3 From 7cdde7537deccd53d95d03860379f3d20ad2e265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Tue, 17 Mar 2015 11:56:14 +0100 Subject: inets: Cleanup of multiple copies of functions Add inets_lib with common functions used by multiple modules --- lib/inets/test/httpc_SUITE.erl | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'lib/inets/test/httpc_SUITE.erl') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 348c75f787..79e2fbca62 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -1889,7 +1889,7 @@ wait4clients(Clients, Timeout) when Timeout > 0 -> {'DOWN', _MRef, process, Pid, normal} -> {value, {Id, _, _}} = lists:keysearch(Pid, 2, Clients), NewClients = lists:keydelete(Id, 1, Clients), - wait4clients(NewClients, Timeout - millisec_passed(Time)); + wait4clients(NewClients, Timeout - inets_lib:millisec_passed(Time)); {'DOWN', _MRef, process, Pid, Reason} -> {value, {Id, _, _}} = lists:keysearch(Pid, 2, Clients), ct:fail({bad_client_termination, Id, Reason}) @@ -1982,17 +1982,6 @@ parse_connection_type(Request) -> "keep-alive" -> keep_alive end. -%% Help function, elapsed milliseconds since T0 -millisec_passed({_,_,_} = T0 ) -> - %% OTP 17 and earlier - timer:now_diff(erlang:now(), T0) div 1000; - -millisec_passed(T0) -> - %% OTP 18 - erlang:convert_time_resolution(erlang:monotonic_time() - T0, - erlang:time_resolution(), - 1000000) div 1000. - set_random_seed() -> %% Adapt to OTP 18 erlang time API and be backwards compatible Unique = try -- cgit v1.2.3