|
49 | 49 | sup_stop_infinity/1, sup_stop_timeout/1, sup_stop_timeout_dynamic/1, |
50 | 50 | sup_stop_brutal_kill/1, sup_stop_brutal_kill_dynamic/1, |
51 | 51 | sup_stop_race/1, sup_stop_non_shutdown_exit_dynamic/1, auto_hibernate/1, |
| 52 | + sup_stop_manual/1, sup_stop_manual_timeout/1, |
| 53 | + sup_stop_race/1, sup_stop_non_shutdown_exit_dynamic/1, |
52 | 54 | child_adm/1, child_adm_simple/1, child_specs/1, child_specs_map/1, |
53 | 55 | extra_return/1, sup_flags/1]). |
54 | 56 |
|
@@ -141,7 +143,8 @@ groups() -> |
141 | 143 | {sup_stop, [], |
142 | 144 | [sup_stop_infinity, sup_stop_timeout, sup_stop_timeout_dynamic, |
143 | 145 | sup_stop_brutal_kill, sup_stop_brutal_kill_dynamic, |
144 | | - sup_stop_race, sup_stop_non_shutdown_exit_dynamic]}, |
| 146 | + sup_stop_race, sup_stop_non_shutdown_exit_dynamic, |
| 147 | + sup_stop_manual, sup_stop_manual_timeout]}, |
145 | 148 | {normal_termination, [], |
146 | 149 | [external_start_no_progress_log, permanent_normal, transient_normal, temporary_normal]}, |
147 | 150 | {shutdown_termination, [], |
@@ -654,6 +657,72 @@ sup_stop_non_shutdown_exit_dynamic(Config) when is_list(Config) -> |
654 | 657 | [temporary, transient, permanent] |
655 | 658 | ). |
656 | 659 |
|
| 660 | +%%------------------------------------------------------------------------- |
| 661 | +%% Tests that children are shut down when a supervisor is stopped via |
| 662 | +%% supervisor:stop/1 |
| 663 | +%% Since supervisors are gen_servers and the basic functionality of the |
| 664 | +%% stop functions is already tested in gen_server_SUITE, we only make |
| 665 | +%% sure that children are terminated correctly when applied to a |
| 666 | +%% supervisor. |
| 667 | +sup_stop_manual(Config) when is_list(Config) -> |
| 668 | + process_flag(trap_exit, true), |
| 669 | + {ok, Pid} = start_link({ok, {{one_for_one, 2, 3600}, []}}), |
| 670 | + Child1 = {child1, {supervisor_1, start_child, []}, |
| 671 | + permanent, brutal_kill, worker, []}, |
| 672 | + Child2 = {child2, {supervisor_1, start_child, []}, |
| 673 | + permanent, 1000, worker, []}, |
| 674 | + Child3 = {child3, {supervisor_1, start_child, []}, |
| 675 | + permanent, 1000, worker, []}, |
| 676 | + {ok, CPid1} = supervisor:start_child(sup_test, Child1), |
| 677 | + link(CPid1), |
| 678 | + {ok, CPid2} = supervisor:start_child(sup_test, Child2), |
| 679 | + link(CPid2), |
| 680 | + {ok, CPid3} = supervisor:start_child(sup_test, Child3), |
| 681 | + link(CPid3), |
| 682 | + |
| 683 | + CPid3 ! {sleep, 100000}, |
| 684 | + |
| 685 | + supervisor:stop(Pid), |
| 686 | + |
| 687 | + check_exit_reason(Pid, normal), |
| 688 | + check_exit_reason(CPid1, killed), |
| 689 | + check_exit_reason(CPid2, shutdown), |
| 690 | + check_exit_reason(CPid3, killed). |
| 691 | + |
| 692 | +%%------------------------------------------------------------------------- |
| 693 | +%% Tests that children are shut down when a supervisor is stopped via |
| 694 | +%% supervisor:stop/3, even if the stop call times out. |
| 695 | +%% Since supervisors are gen_servers and the basic functionality of the |
| 696 | +%% stop functions is already tested in gen_server_SUITE, we only make |
| 697 | +%% sure that children are terminated correctly when applied to a |
| 698 | +%% supervisor. |
| 699 | +sup_stop_manual_timeout(Config) when is_list(Config) -> |
| 700 | + process_flag(trap_exit, true), |
| 701 | + {ok, Pid} = start_link({ok, {{one_for_one, 2, 3600}, []}}), |
| 702 | + Child1 = {child1, {supervisor_1, start_child, []}, |
| 703 | + permanent, 5000, worker, []}, |
| 704 | + Child2 = {child2, {supervisor_1, start_child, []}, |
| 705 | + permanent, 1000, worker, []}, |
| 706 | + {ok, CPid1} = supervisor:start_child(sup_test, Child1), |
| 707 | + link(CPid1), |
| 708 | + {ok, CPid2} = supervisor:start_child(sup_test, Child2), |
| 709 | + link(CPid2), |
| 710 | + |
| 711 | + CPid1 ! {sleep, 1000}, |
| 712 | + |
| 713 | + try |
| 714 | + supervisor:stop(Pid, normal, 100) |
| 715 | + of |
| 716 | + ok -> ct:fail(expected_timeout) |
| 717 | + catch |
| 718 | + exit:timeout -> |
| 719 | + ok |
| 720 | + end, |
| 721 | + |
| 722 | + check_exit_reason(Pid, normal), |
| 723 | + check_exit_reason(CPid1, shutdown), |
| 724 | + check_exit_reason(CPid2, shutdown). |
| 725 | + |
657 | 726 | %%------------------------------------------------------------------------- |
658 | 727 | %% The start function provided to start a child may return {ok, Pid} |
659 | 728 | %% or {ok, Pid, Info}, if it returns the latter check that the |
|
0 commit comments