File 0861-megaco-test-Try-handling-of-timetrap-timeout.patch of Package erlang
From 8160967924bef618fa33fe7de7e749cddb871bd0 Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Mon, 17 Jan 2022 19:19:18 +0100
Subject: [PATCH 1/6] [megaco|test] Try "handling" of timetrap timeout
---
lib/megaco/test/megaco_test_lib.erl | 45 ++++++++++++++++++++++++++---
lib/megaco/test/megaco_test_lib.hrl | 3 ++
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/lib/megaco/test/megaco_test_lib.erl b/lib/megaco/test/megaco_test_lib.erl
index b7912a9f49..3fca55f68b 100644
--- a/lib/megaco/test/megaco_test_lib.erl
+++ b/lib/megaco/test/megaco_test_lib.erl
@@ -49,6 +49,7 @@
display_alloc_info/0,
display_system_info/1, display_system_info/2, display_system_info/3,
+ executor/1, executor/2,
try_tc/6,
prepare_test_case/5,
@@ -2094,6 +2095,42 @@ reset_kill_timer(Config) ->
end.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+executor(Fun) ->
+ executor(Fun, infinity).
+
+executor(Fun, Timeout)
+ when is_function(Fun, 0) andalso
+ ((Timeout =:= infinity) orelse (is_integer(Timeout) andalso (Timeout > 0))) ->
+ {Pid, MRef} = erlang:spawn_monitor(Fun),
+ receive
+ {'DOWN', MRef, process, Pid, Info} ->
+ p("executor process terminated with"
+ "~n ~p", [Info]),
+ Info;
+ {'EXIT', TCPid, {timetrap_timeout = R, TCTimeout, TCSTack}} ->
+ p("received timetrap timeout (~w ms) from ~p => Kill executor process"
+ "~n TC Stack: ~p", [TCTimeout, TCPid, TCSTack]),
+ exit(Pid, kill),
+ %% We do this in case we get some info about 'where'
+ %% the process is hanging...
+ receive
+ {'DOWN', MRef, process, Pid, Info} ->
+ p("executor process terminated with"
+ "~n ~p", [Info]),
+ ok
+ after 1000 -> % Give it a second...
+ ok
+ end,
+ {error, R}
+ after Timeout ->
+ p("received timeout - kill executor process"),
+ exit(kill, Pid),
+ {error, executor_timeout}
+ end.
+
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
try_tc(TCName, Name, Verbosity, Pre, Case, Post)
@@ -2111,23 +2148,23 @@ try_tc(TCName, Name, Verbosity, Pre, Case, Post)
try Case(State) of
Res ->
p("try_tc -> test case done: try post"),
- (catch Post(State)),
+ _ = executor(fun() -> Post(State) end),
p("try_tc -> done"),
Res
catch
throw:{skip, _} = SKIP:_ ->
p("try_tc -> test case (throw) skip: try post"),
- (catch Post(State)),
+ _ = executor(fun() -> Post(State) end),
p("try_tc -> test case (throw) skip: done"),
SKIP;
exit:{skip, _} = SKIP:_ ->
p("try_tc -> test case (exit) skip: try post"),
- (catch Post(State)),
+ _ = executor(fun() -> Post(State) end),
p("try_tc -> test case (exit) skip: done"),
SKIP;
C:E:S ->
p("try_tc -> test case failed: try post"),
- (catch Post(State)),
+ _ = executor(fun() -> Post(State) end),
case megaco_test_global_sys_monitor:events() of
[] ->
p("try_tc -> test case failed: done"),
diff --git a/lib/megaco/test/megaco_test_lib.hrl b/lib/megaco/test/megaco_test_lib.hrl
index 9e69fecf40..face081026 100644
--- a/lib/megaco/test/megaco_test_lib.hrl
+++ b/lib/megaco/test/megaco_test_lib.hrl
@@ -85,6 +85,9 @@
-define(MULTI_RECEIVE(Expected),
?VERIFY(lists:sort(Expected), lists:sort(?LIB:flush()))).
+-define(EXEC(F), ?LIB:executor(F)).
+-define(EXEC(F, TO), ?LIB:executor(F, TO)).
+
-define(TRY_TC(TCN, N, V, PRE, CASE, POST),
?LIB:try_tc(TCN, N, V, PRE, CASE, POST)).
--
2.31.1