File 0134-application_master-Test-that-stop-callback-is-called.patch of Package erlang

From 57fd443ea118afe1da2b1eac9a3d5340672136ca Mon Sep 17 00:00:00 2001
From: Rickard Green <rickard@erlang.org>
Date: Mon, 9 Mar 2020 14:30:44 +0100
Subject: [PATCH 2/2] application_master: Test that stop callback is called

also when application master dies
---
 lib/kernel/test/application_SUITE.erl | 23 ++++++++++++++++++++---
 lib/kernel/test/ch_sup.erl            |  8 +++++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/kernel/test/application_SUITE.erl b/lib/kernel/test/application_SUITE.erl
index 1ab554db7c..916eba31a6 100644
--- a/lib/kernel/test/application_SUITE.erl
+++ b/lib/kernel/test/application_SUITE.erl
@@ -32,7 +32,7 @@
 	 otp_5606/1,
 	 start_phases/1, get_key/1, get_env/1,
 	 permit_false_start_local/1, permit_false_start_dist/1, script_start/1, 
-	 nodedown_start/1, init2973/0, loop2973/0, loop5606/1]).
+	 nodedown_start/1, init2973/0, loop2973/0, loop5606/1, otp_16504/1]).
 
 -export([config_change/1, persistent_env/1,
 	 distr_changed_tc1/1, distr_changed_tc2/1,
@@ -62,7 +62,7 @@ groups() ->
     [{reported_bugs, [],
       [otp_1586, otp_2078, otp_2012, otp_2718, otp_2973,
        otp_3002, otp_3184, otp_4066, otp_4227, otp_5363,
-       otp_5606]},
+       otp_5606, otp_16504]},
      {distr_changed, [],
       [distr_changed_tc1, distr_changed_tc2]}].
 
@@ -1565,7 +1565,24 @@ loop5606(Pid) ->
 	    Res = application:start(app1),
 	    Pid ! {self(), Res}
     end.
-	    
+
+otp_16504(Config) when is_list(Config) ->
+    {ok, Fd} = file:open("app1.app", [write]),
+    w_app1(Fd),
+    file:close(Fd),
+    register(test_application_stop_called, self()),
+
+    ok = application:ensure_started(app1),
+    Master = application_controller:get_master(app1),
+    exit(Master, kill),
+    receive
+        {stop_called, _} ->
+            ok
+    after 3000 ->
+            ct:fail(stop_not_called)
+    end,
+    ok.
+
 %% Tests get_env/* functions.
 get_env(Conf) when is_list(Conf) ->
     {ok, _}   = application:get_env(kernel, error_logger),
diff --git a/lib/kernel/test/ch_sup.erl b/lib/kernel/test/ch_sup.erl
index 1d7f17fc95..f0ec2d1e72 100644
--- a/lib/kernel/test/ch_sup.erl
+++ b/lib/kernel/test/ch_sup.erl
@@ -32,7 +32,13 @@ start(_Type, {_AppN, Low, High}) ->
 				    lists:seq(Low, High)),
     {ok, P, []}.
 
-stop(_) -> ok.
+stop(State) ->
+    case whereis(test_application_stop_called) of
+        undefined ->
+            ok;
+        Pid ->
+            Pid ! {stop_called, State}
+    end.
  
 start_phase(_Phase, _Type, _Args) ->
     ok.
-- 
2.16.4

openSUSE Build Service is sponsored by