From e10385909c687590d6522d007bba9d72f3f5c380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erland=20Sch=C3=B6nbeck?= Date: Tue, 24 Mar 2015 13:52:07 +0100 Subject: inets: Add new module inets_time_compat with new time API The new module is backwards compatible. --- lib/inets/test/ftp_suite_lib.erl | 13 +++---------- lib/inets/test/httpc_SUITE.erl | 21 ++++----------------- lib/inets/test/httpd_time_test.erl | 11 +---------- 3 files changed, 8 insertions(+), 37 deletions(-) (limited to 'lib/inets/test') diff --git a/lib/inets/test/ftp_suite_lib.erl b/lib/inets/test/ftp_suite_lib.erl index 5ae9eb736e..b637832101 100644 --- a/lib/inets/test/ftp_suite_lib.erl +++ b/lib/inets/test/ftp_suite_lib.erl @@ -29,7 +29,6 @@ % -export([init_per_testcase/2, end_per_testcase/2]). -compile(export_all). --compile([{nowarn_deprecated_function,{erlang,now,0}}]). -record(progress, { @@ -1353,15 +1352,9 @@ do_delete(Pid, Config) -> ok. do_mkdir(Pid) -> - %% Adapt to OTP 18 erlang time API and be backwards compatible - NewDir = try - "earl_" ++ integer_to_list(erlang:unique_integer([positive])) - catch - error:undef -> - {A, B, C} = erlang:now(), - "nisse_" ++ integer_to_list(A) ++ "_" ++ - integer_to_list(B) ++ "_" ++ integer_to_list(C) - end, + NewDir = "earl_" ++ + integer_to_list(inets_time_compat:unique_integer([positive])), + ok = ftp:cd(Pid, "incoming"), {ok, CurrDir} = ftp:pwd(Pid), {error, efnamena} = ftp:mkdir(Pid, NewDir++"\r\nCWD ."), diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 2193588031..0dfc65e8f7 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -31,7 +31,6 @@ -include("httpc_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://"). @@ -1934,14 +1933,8 @@ run_clients(NumClients, ServerPort, SeqNumServer) -> wait4clients([], _Timeout) -> ok; wait4clients(Clients, Timeout) when Timeout > 0 -> - %% Adapt to OTP 18 erlang time API and be backwards compatible - Time = try - erlang:monotonic_time() - catch - error:undef -> - %% Use Erlang system time as monotonic time - erlang:now() - end, + Time = inets_time_compat:monotonic_time(), + receive {'DOWN', _MRef, process, Pid, normal} -> {value, {Id, _, _}} = lists:keysearch(Pid, 2, Clients), @@ -2040,14 +2033,8 @@ parse_connection_type(Request) -> end. set_random_seed() -> - %% Adapt to OTP 18 erlang time API and be backwards compatible - Unique = try - erlang:unique_integer() - catch - error:undef -> - {MS, S, US} = erlang:now(), - (MS*1000000+S)*1000000+US - end, + Unique = inets_time_compat:unique_integer(), + A = erlang:phash2([make_ref(), self(), Unique]), random:seed(A, A, A). diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index b3e6746a01..7dd61a5517 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -18,7 +18,6 @@ %% %% -module(httpd_time_test). --compile([{nowarn_deprecated_function,{erlang,now,0}}]). -export([t/3, t1/2, t2/2, t4/2]). @@ -117,15 +116,7 @@ main(N, SocketType, Host, Port, Time) loop(Pollers, Timeout) -> d("loop -> entry when" "~n Timeout: ~p", [Timeout]), - %% Adapt to OTP 18 erlang time API and be backwards compatible - Start = try - erlang:monotonic_time(1000) - catch - error:undef -> - %% Use Erlang system time as monotonic time - {A,B,C} = erlang:now(), - A*1000000000+B*1000+(C div 1000) - end, + Start = inets_time_compat:monotonic_time(), receive {'EXIT', Pid, {poller_stat_failure, SocketType, Host, Port, Time, Reason}} -> -- cgit v1.2.3