summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2012-09-03 16:43:52 +0100
committerTim Watson <tim@rabbitmq.com>2012-09-03 16:43:52 +0100
commit6db853fb28bc092e39f956919ba4b8bd1031cec8 (patch)
tree904503d75a3fd7489e9045fa4b2104455fec543f
parentd43da6ef1a8de96ae08f48bde55b0e38fa6d2e2d (diff)
downloadrabbitmq-server-6db853fb28bc092e39f956919ba4b8bd1031cec8.tar.gz
Introduce additional, non-smp tests (using suspend) and explode the test
fixture list to create 400 repetitions of the group
-rw-r--r--src/supervisor2_tests.erl61
1 files changed, 54 insertions, 7 deletions
diff --git a/src/supervisor2_tests.erl b/src/supervisor2_tests.erl
index c4916791..342dce27 100644
--- a/src/supervisor2_tests.erl
+++ b/src/supervisor2_tests.erl
@@ -20,6 +20,8 @@
-export([test_all/0, start_sup/0, start_link/0, start_child/0]).
-export([init/1]).
+-define(NUM_CHILDREN, 1000).
+
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
@@ -28,11 +30,20 @@ test_all() ->
eunit:test(supervisor2, [verbose]).
terminate_simple_children_without_deadlock_test_() ->
- [{setup, fun init_supervisor/0,
- {with, [fun ensure_children_are_alive/1,
- fun shutdown_and_verify_all_children_died/1]}},
- {setup, fun init_supervisor/0,
- {with, [fun shutdown_whilst_interleaving_exits_occur/1]}}].
+ lists:flatten(
+ lists:duplicate(
+ 100,[{setup, fun init_supervisor/0,
+ {with, [fun ensure_children_are_alive/1,
+ fun shutdown_and_verify_all_children_died/1]}},
+ {setup, fun init_supervisor/0,
+ {with, [fun shutdown_whilst_interleaving_exits_occur/1]}},
+ {setup,
+ fun() -> erlang:system_flag(multi_scheduling, block),
+ ?MODULE:init_supervisor()
+ end,
+ fun(_) -> erlang:system_flag(multi_scheduling, unblock) end,
+ {with,
+ [fun shutdown_with_exits_attempting_to_overtake_downs/1]}}])).
%%
%% Public (test facing) API
@@ -79,6 +90,40 @@ shutdown_and_verify_all_children_died({Parent, ChildPids}=State) ->
erlang:is_process_alive(P)]),
?assertEqual(false, erlang:is_process_alive(TestSup)).
+shutdown_with_exits_attempting_to_overtake_downs({Parent, ChildPids}=State) ->
+ erlang:process_flag(priority, high),
+ ensure_children_are_alive(State),
+ TestPid = self(),
+ TestSup = erlang:whereis(?MODULE),
+ Ref = erlang:make_ref(),
+
+ ?debugFmt("Suspending process ~p~n",
+ [TestSup]),
+ true = erlang:suspend_process(TestSup),
+
+ spawn(fun() ->
+ ?debugFmt("supervisor2:terminate_child/2 call in progress~n",
+ []),
+ TestPid ! {Ref, supervisor2:terminate_child(Parent, test_sup)}
+ end),
+ erlang:yield(),
+
+ ?debugFmt("Killing ~p child pids~n", [length(ChildPids)]),
+ [P ! stop || P <- ChildPids],
+
+ ?debugFmt("Resuming process ~p~n", [TestSup]),
+ erlang:resume_process(TestSup),
+
+ erlang:yield(),
+ ?debugVal(erlang:is_process_alive(TestSup)),
+ ?debugFmt("Awaiting response from kill coordinator~n", []),
+ receive {Ref, Res} ->
+ ?assertEqual(ok, Res)
+ end,
+ ?assertMatch([], [P || P <- ChildPids,
+ erlang:is_process_alive(P)]),
+ ok.
+
shutdown_whilst_interleaving_exits_occur({Parent, ChildPids}=State) ->
ensure_children_are_alive(State),
TestPid = self(),
@@ -93,8 +138,10 @@ shutdown_whilst_interleaving_exits_occur({Parent, ChildPids}=State) ->
init_supervisor() ->
{ok, Pid} = supervisor2:start_link(?MODULE, [parent]),
- {Pid, [start_child() || _ <- lists:seq(1, 100)]}.
+ {Pid, [start_child() || _ <- lists:seq(1, ?NUM_CHILDREN)]}.
loop_infinity() ->
- loop_infinity().
+ receive
+ stop -> ok
+ end.