aboutsummaryrefslogtreecommitdiffstats
path: root/lib/test_server/src/test_server.erl
diff options
context:
space:
mode:
authorPeter Andersson <[email protected]>2011-09-28 17:43:26 +0200
committerPeter Andersson <[email protected]>2011-09-28 22:53:44 +0200
commitb7f1a0861daa57db115b358927293d98e1630810 (patch)
treef873f49ddeda26ff656bc7e2394028daee118684 /lib/test_server/src/test_server.erl
parent001f0a4baa95ccc6eb553cad9e4551b4e520dc8b (diff)
downloadotp-b7f1a0861daa57db115b358927293d98e1630810.tar.gz
otp-b7f1a0861daa57db115b358927293d98e1630810.tar.bz2
otp-b7f1a0861daa57db115b358927293d98e1630810.zip
Add missing tests for timetrap handling and fix remaining errors
OTP-9593
Diffstat (limited to 'lib/test_server/src/test_server.erl')
-rw-r--r--lib/test_server/src/test_server.erl61
1 files changed, 42 insertions, 19 deletions
diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl
index e1a139af6f..12625e3c00 100644
--- a/lib/test_server/src/test_server.erl
+++ b/lib/test_server/src/test_server.erl
@@ -1921,30 +1921,53 @@ time_ms({seconds,N}) -> seconds(N);
time_ms({Other,_N}) ->
format("=== ERROR: Invalid time specification: ~p. "
"Should be seconds, minutes, or hours.~n", [Other]),
- exit({invalid_time_spec,Other});
+ exit({invalid_time_format,Other});
time_ms(Ms) when is_integer(Ms) -> Ms;
time_ms(infinity) -> infinity;
time_ms(Fun) when is_function(Fun) ->
- try Fun() of
- Val -> time_ms1(Val)
- catch
- _:Error ->
- exit({timetrap_error,Error})
- end;
-time_ms({M,F,A}) when is_atom(M), is_atom(F), is_list(A) ->
- try apply(M, F, A) of
- Val -> time_ms1(Val)
- catch
- _:Error ->
+ time_ms_apply(Fun);
+time_ms({M,F,A}=MFA) when is_atom(M), is_atom(F), is_list(A) ->
+ time_ms_apply(MFA);
+time_ms(Other) -> exit({invalid_time_format,Other}).
+
+time_ms_apply(Func) ->
+ time_ms_apply(Func, [5000,30000,60000,infinity]).
+
+time_ms_apply(Func, TOs) ->
+ Apply = fun() ->
+ case Func of
+ {M,F,A} ->
+ exit({self(),apply(M, F, A)});
+ Fun ->
+ exit({self(),Fun()})
+ end
+ end,
+ Pid = spawn(Apply),
+ Ref = monitor(process, Pid),
+ time_ms_wait(Func, Pid, Ref, TOs).
+
+time_ms_wait(Func, Pid, Ref, [TO|TOs]) ->
+ receive
+ {'DOWN',Ref,process,Pid,{Pid,Result}} ->
+ time_ms_check(Result);
+ {'DOWN',Ref,process,Pid,Error} ->
exit({timetrap_error,Error})
+ after
+ TO ->
+ format("=== WARNING: No return from timetrap function ~p~n", [Func]),
+ time_ms_wait(Func, Pid, Ref, TOs)
end;
-time_ms(Other) -> exit({invalid_time_spec,Other}).
-
-time_ms1(MFA = {M,F,A}) when is_atom(M), is_atom(F), is_list(A) ->
- exit({invalid_time_spec,MFA});
-time_ms1(Fun) when is_function(Fun) ->
- exit({invalid_time_spec,Fun});
-time_ms1(Other) ->
+%% this clause will never execute if 'infinity' is in TOs list, that's ok!
+time_ms_wait(Func, Pid, Ref, []) ->
+ demonitor(Ref),
+ exit(Pid, kill),
+ exit({timetrap_error,{no_return_from_timetrap_function,Func}}).
+
+time_ms_check(MFA = {M,F,A}) when is_atom(M), is_atom(F), is_list(A) ->
+ exit({invalid_time_format,MFA});
+time_ms_check(Fun) when is_function(Fun) ->
+ exit({invalid_time_format,Fun});
+time_ms_check(Other) ->
time_ms(Other).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%