diff options
Diffstat (limited to 'lib/stdlib/test/supervisor_bridge_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/supervisor_bridge_SUITE.erl | 108 |
1 files changed, 53 insertions, 55 deletions
diff --git a/lib/stdlib/test/supervisor_bridge_SUITE.erl b/lib/stdlib/test/supervisor_bridge_SUITE.erl index b3056ff41a..279ae91cdc 100644 --- a/lib/stdlib/test/supervisor_bridge_SUITE.erl +++ b/lib/stdlib/test/supervisor_bridge_SUITE.erl @@ -1,18 +1,19 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2011. All Rights Reserved. +%% Copyright Ericsson AB 1996-2016. All Rights Reserved. %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. -%% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. %% %% %CopyrightEnd% %% @@ -23,13 +24,15 @@ simple_global_supervisor/1]). -export([client/1,init/1,internal_loop_init/1,terminate/2,server9212/0]). --include_lib("test_server/include/test_server.hrl"). +-include_lib("common_test/include/ct.hrl"). -define(bridge_name,supervisor_bridge_SUITE_server). -define(work_bridge_name,work_supervisor_bridge_SUITE_server). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [starting, mini_terminate, mini_die, badstart, simple_global_supervisor]. @@ -52,33 +55,30 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -starting(suite) -> []; starting(Config) when is_list(Config) -> process_flag(trap_exit,true), - ?line ignore = start(1), - ?line {error,testing} = start(2), + ignore = start(1), + {error,testing} = start(2), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -mini_terminate(suite) -> []; mini_terminate(Config) when is_list(Config) -> miniappl(1), ok. -mini_die(suite) -> []; mini_die(Config) when is_list(Config) -> miniappl(2), ok. miniappl(N) -> process_flag(trap_exit,true), - ?line {ok,Server} = start(3), - ?line Client = spawn_link(?MODULE,client,[N]), - ?line Handle = test_server:timetrap(2000), - ?line miniappl_loop(Client,Server), - ?line test_server:timetrap_cancel(Handle). + {ok,Server} = start(3), + Client = spawn_link(?MODULE,client,[N]), + ct:timetrap({seconds,2}), + miniappl_loop(Client, Server). + miniappl_loop([],[]) -> ok; @@ -86,19 +86,19 @@ miniappl_loop(Client,Server) -> io:format("Client ~p, Server ~p\n",[Client,Server]), receive {'EXIT',Client,_} -> - ?line miniappl_loop([],Server); + miniappl_loop([],Server); {'EXIT',Server,killed} -> %% terminate - ?line miniappl_loop(Client,[]); + miniappl_loop(Client,[]); {'EXIT',Server,died} -> %% die - ?line miniappl_loop(Client,[]); + miniappl_loop(Client,[]); {dying,_Reason} -> - ?line miniappl_loop(Client, Server); + miniappl_loop(Client, Server); Other -> - ?line exit({failed,Other}) + exit({failed,Other}) end. %%%%%%%%%%%%%%%%%%%% -% Client +%% Client client(N) -> io:format("Client starting...\n"), @@ -111,7 +111,7 @@ client(N) -> exit(fine). %%%%%%%%%%%%%%%%%%%% -% Non compliant server +%% Non compliant server start(N) -> supervisor_bridge:start_link({local,?bridge_name},?MODULE,N). @@ -169,45 +169,44 @@ terminate(_Reason, _State) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -badstart(suite) -> []; -badstart(doc) -> "Test various bad ways of starting a supervisor bridge."; +%% Test various bad ways of starting a supervisor bridge. badstart(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:minutes(1)), - %% Various bad arguments. - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link({xxx,?bridge_name},?MODULE,1)), - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link({local,"foo"},?MODULE,1)), - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link(?bridge_name,?MODULE,1)), - ?line [] = test_server:messages_get(), % No messages waiting + receive + Msg -> + ct:fail({unexpected,Msg}) + after 1 -> + ok + end, %% Already started. - ?line process_flag(trap_exit, true), - ?line {ok,Pid} = + process_flag(trap_exit, true), + {ok,Pid} = supervisor_bridge:start_link({local,?bridge_name},?MODULE,3), - ?line {error,{already_started,Pid}} = + {error,{already_started,Pid}} = supervisor_bridge:start_link({local,?bridge_name},?MODULE,3), - ?line public_kill(), + public_kill(), %% We used to wait 1 ms before retrieving the message queue, %% but that might not always be enough if the machine is overloaded. - ?line receive - {'EXIT', Pid, killed} -> ok - end, - ?line test_server:timetrap_cancel(Dog), + receive + {'EXIT', Pid, killed} -> ok + end, ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% OTP-9212. Restart of global supervisor. -simple_global_supervisor(suite) -> []; -simple_global_supervisor(doc) -> "Globally registered supervisor."; +%% Globally registered supervisor. simple_global_supervisor(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap({seconds,10}), Child = {child, {?MODULE,server9212,[]}, permanent, 2000, worker, []}, InitResult = {ok, {{one_for_all,3,60}, [Child]}}, @@ -215,16 +214,15 @@ simple_global_supervisor(Config) when is_list(Config) -> supervisor:start_link({local,bridge9212}, ?MODULE, {4,InitResult}), BN_1 = global:whereis_name(?bridge_name), - ?line exit(BN_1, kill), + exit(BN_1, kill), timer:sleep(200), BN_2 = global:whereis_name(?bridge_name), - ?line true = is_pid(BN_2), - ?line true = BN_1 =/= BN_2, + true = is_pid(BN_2), + true = BN_1 =/= BN_2, - ?line process_flag(trap_exit, true), + process_flag(trap_exit, true), exit(Sup, kill), - ?line receive {'EXIT', Sup, killed} -> ok end, - ?line test_server:timetrap_cancel(Dog), + receive {'EXIT', Sup, killed} -> ok end, ok. server9212() -> |