File 0521-megaco-test-Tweaked-load-suite.patch of Package erlang

From 918165d00a81170bcf17ec26eaaaded42db42aae Mon Sep 17 00:00:00 2001
From: Micael Karlberg <bmk@erlang.org>
Date: Tue, 16 Mar 2021 12:19:50 +0100
Subject: [PATCH 1/4] [megaco|test] Tweaked load suite

Actually what was tweaked was the start of the utility mgc and mg
used by "all" megaco test suites.
Instead of using spawn_link, use spawn_monitor.
A problem detected in one of the load test cases eaddrinuse
was supposed to be catched (and converted to a skip) in the mgc
start (there was code for it) but was not. Instead it was catched
at the top level, as an error.
---
 lib/megaco/test/megaco_load_SUITE.erl |  4 +-
 lib/megaco/test/megaco_test_mg.erl    | 36 ++++++++---------
 lib/megaco/test/megaco_test_mgc.erl   | 57 ++++++++++++++++++++++-----
 3 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/lib/megaco/test/megaco_load_SUITE.erl b/lib/megaco/test/megaco_load_SUITE.erl
index 876e16ecfb..d033e137ec 100644
--- a/lib/megaco/test/megaco_load_SUITE.erl
+++ b/lib/megaco/test/megaco_load_SUITE.erl
@@ -60,8 +60,8 @@
 -define(SINGLE_USER_LOAD_NUM_REQUESTS, 1000).
 -define(MULTI_USER_LOAD_NUM_REQUESTS,  1000).
 
--define(MGC_START(Pid, Mid, ET, Conf, Verb), 
-        megaco_test_mgc:start(Pid, Mid, ET, 
+-define(MGC_START(Node, Mid, ET, Conf, Verb), 
+        megaco_test_mgc:start(Node, Mid, ET, 
 			      [{megaco_trace, false}] ++ Conf, Verb)).
 -define(MGC_STOP(Pid), megaco_test_mgc:stop(Pid)).
 -define(MGC_USER_INFO(Pid,Tag), megaco_test_mgc:user_info(Pid,Tag)).
diff --git a/lib/megaco/test/megaco_test_mg.erl b/lib/megaco/test/megaco_test_mg.erl
index 5979466785..e84adc7de6 100644
--- a/lib/megaco/test/megaco_test_mg.erl
+++ b/lib/megaco/test/megaco_test_mg.erl
@@ -110,32 +110,28 @@ start(Node, Mid, Encoding, Transport, Conf, Verbosity) ->
 		case (catch mg(Self, Verbosity, Config)) of
 		    {'EXIT', Reason} ->
 			e("LOADER(~p,~p) terminating with exit"
-                          "~n      ~p", [self(), node(), Reason]),
+                          "~n      ~p", [Self, node(), Reason]),
 			exit(Reason);
 		    Else ->
 			i("LOADER(~p,~p) terminating with"
-                          "~n      ~p", [self(), node(), Else]),
+                          "~n      ~p", [Self, node(), Else]),
 			Else
 		end
 	end,
-    true = erlang:monitor_node(Node, true),
-    Pid = spawn_link(Node, Fun),
-    %% Pid = spawn_link(Node, ?MODULE, mg, [self(), Verbosity, Config]),
-    MonRef = (catch erlang:monitor(process, Pid)),
-    NodePing = net_adm:ping(Node), 
-    ProcInfo = (catch proc_info(Pid)), 
-    i("start -> "
-      "~n      self():           ~p"
-      "~n      node():           ~p"
-      "~n      net_adm:ping(~p): ~p" 
-      "~n      Loader:           ~p"
-      "~n      Monitor ref:      ~p"
-      "~n      Process info:     ~p", 
-      [self(), node(), 
-       Node, NodePing, 
-       Pid, 
-       MonRef, ProcInfo]),
-    await_started(Node, MonRef, Pid).
+    true        = erlang:monitor_node(Node, true),
+    {Pid, MRef} = spawn_monitor(Node, Fun),
+    NodePing    = net_adm:ping(Node),
+    ProcInfo    = (catch proc_info(Pid)),
+    i("start mg[~p] -> ~p"
+      "~n      self():       ~p"
+      "~n      node():       ~p"
+      "~n      Node ping:    ~p" 
+      "~n      Loader:       ~p"
+      "~n      Monitor ref:  ~p"
+      "~n      Process info: ~p", 
+      [Node, Pid,
+       Self, node(), NodePing, Pid, MRef, ProcInfo]),
+    await_started(Node, MRef, Pid).
 
 proc_info(Pid) ->
     rpc:call(node(Pid), erlang, process_info, [Pid]).
diff --git a/lib/megaco/test/megaco_test_mgc.erl b/lib/megaco/test/megaco_test_mgc.erl
index 1204dbba07..a7d0731b0f 100644
--- a/lib/megaco/test/megaco_test_mgc.erl
+++ b/lib/megaco/test/megaco_test_mgc.erl
@@ -93,10 +93,27 @@ start(Node, Mid, ET, Conf, Verbosity) ->
     d("start mgc[~p]: ~p"
       "~n      ET:   ~p"
       "~n      Conf: ~p", [Node, Mid, ET, Conf]),
-    RI = {receive_info, mk_recv_info(ET)},
-    Config = [{local_mid, Mid}, RI] ++ Conf,
-    Pid = spawn_link(Node, ?MODULE, mgc, [self(), Verbosity, Config]),
-    await_started(Pid).
+    RI          = {receive_info, mk_recv_info(ET)},
+    Config      = [{local_mid, Mid}, RI] ++ Conf,
+    Self        = self(),
+    true        = erlang:monitor_node(Node, true),
+    MGC         = fun() -> mgc(Self, Verbosity, Config) end,
+    {Pid, MRef} = spawn_monitor(Node, MGC),
+    NodePing    = net_adm:ping(Node),
+    ProcInfo    = (catch proc_info(Pid)),
+    i("start mgc[~p] -> ~p"
+      "~n      self():       ~p"
+      "~n      node():       ~p"
+      "~n      Node ping:    ~p" 
+      "~n      Loader:       ~p"
+      "~n      Monitor ref:  ~p"
+      "~n      Process info: ~p", 
+      [Node, Pid,
+       Self, node(), NodePing, Pid, MRef, ProcInfo]),
+    await_started(Node, Pid, MRef).
+
+proc_info(Pid) ->
+    rpc:call(node(Pid), erlang, process_info, [Pid]).
 
 mk_recv_info(ET) ->
     mk_recv_info(ET, []).
@@ -155,20 +172,40 @@ select_transport(Transport) ->
     throw({error, {invalid_transport, Transport}}).
 
 
-await_started(Pid) ->
+await_started(Node, Pid, MRef) ->
     receive
 	{started, Pid} ->
-	    d("await_started ~p: ok", [Pid]),
+	    i("await_started ~p: ok", [Pid]),
+	    true = erlang:monitor_node(Node, false),	    
+	    erlang:demonitor(MRef),
 	    {ok, Pid};
-	{'EXIT', Pid, 
-	 {failed_starting_tcp_listen, {could_not_start_listener, {gen_tcp_listen, eaddrinuse}}}} ->
+
+	{nodedown, Node} ->
+	    i("await_started ~p - received node down", [Pid]),
+	    exit({node_down, Node}); 
+
+        {'DOWN', MRef, process, Pid, 
+         {failed_starting_tcp_listen,
+          {could_not_start_listener, {gen_tcp_listen, eaddrinuse}}}} ->
 	    e("await_started ~p: address already in use", [Pid]),
+	    true = erlang:monitor_node(Node, false),	    
 	    ?SKIP(eaddrinuse);
-	{'EXIT', Pid, Reason} ->
+
+        {'DOWN', MRef, process, Pid, Reason} ->
 	    e("await_started ~p: received exit signal: ~p", [Pid, Reason]),
+	    true = erlang:monitor_node(Node, false),	    
 	    exit({failed_starting, Pid, Reason})
+
     after 10000 ->
-	    e("await_started ~p: timeout", [Pid]),
+	    NodePing = net_adm:ping(Node), 
+	    ProcInfo = (catch proc_info(Pid)),
+	    FlushQ = megaco_test_lib:flush(), 
+	    e("await_started ~p - timeout: "
+	      "~n      net_adm:ping(~p):     ~p" 
+	      "~n      Process info:         ~p"
+	      "~n      Messages in my queue: ~p", 
+	      [Pid, Node, NodePing, ProcInfo, FlushQ]),
+	    true = erlang:monitor_node(Node, false),	    
 	    exit({error, timeout})
     end.
 
-- 
2.26.2

openSUSE Build Service is sponsored by