Skip to content

Commit 5e97803

Browse files
committed
Fix some bugs in test_supervisor.erl
Fixes some tests to catch the messages from child ping_pong_servers so they will not be received by later tests. Changes the supervisor started in test_count_children to use a generic supervisor without a child, rather than using the modules start_link which always starts a child ping_pong_server that sends messages back to the test environment. Fixes the test_ping_ping final `recieve` to match on a new `Pid4` (which would indicate a restart) rather than `Pid3` that the monitor just caught the 'DOWN' message for. Signed-off-by: Winford <[email protected]>
1 parent a4fb6db commit 5e97803

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/libs/estdlib/test_supervisor.erl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,24 @@ test_count_children() ->
9595
[{specs, 0}, {active, 0}, {supervisors, 0}, {workers, 0}] = supervisor:count_children(SupPid),
9696

9797
% Add a worker child and verify counts
98-
{ok, _ChildPid} = supervisor:start_child(SupPid, #{
98+
{ok, ChildPid} = supervisor:start_child(SupPid, #{
9999
id => test_worker,
100100
start => {ping_pong_server, start_link, [self()]},
101101
restart => permanent,
102102
shutdown => 5000,
103103
type => worker
104104
}),
105105

106+
% Receive message sent back so it won't be left for another test to receive erroneously.
107+
ChildPid = get_and_test_server(),
108+
106109
% Check count_children with one active worker
107110
[{specs, 1}, {active, 1}, {supervisors, 0}, {workers, 1}] = supervisor:count_children(SupPid),
108111

109-
% Add a supervisor child and verify counts
112+
% Add a supervisor child with no children and verify counts
110113
{ok, _SupervisorPid} = supervisor:start_child(SupPid, #{
111114
id => test_supervisor,
112-
start => {?MODULE, start_link, [self()]},
115+
start => {supervisor, start_link, [?MODULE, {test_no_child, self()}]},
113116
restart => permanent,
114117
shutdown => infinity,
115118
type => supervisor
@@ -234,8 +237,8 @@ test_ping_pong(SupPid) ->
234237
end,
235238
no_restart =
236239
receive
237-
{ping_pong_server_ready, Pid3} ->
238-
Pid3
240+
{ping_pong_server_ready, Pid4} ->
241+
Pid4
239242
after 100 -> no_restart
240243
end,
241244
unlink(SupPid),
@@ -317,14 +320,17 @@ test_which_children() ->
317320
[] = supervisor:which_children(SupPid),
318321

319322
% Add a child and test
320-
{ok, _ChildPid} = supervisor:start_child(SupPid, #{
323+
{ok, ChildPid} = supervisor:start_child(SupPid, #{
321324
id => test_child,
322325
start => {ping_pong_server, start_link, [self()]},
323326
restart => permanent,
324327
shutdown => 5000,
325328
type => worker
326329
}),
327330

331+
% Receive message sent back so it won't be left for another test to receive erroneously.
332+
ChildPid = get_and_test_server(),
333+
328334
% Check which_children returns the child info
329335
[{test_child, ChildPid, worker, [ping_pong_server]}] = supervisor:which_children(SupPid),
330336
true = is_pid(ChildPid),

0 commit comments

Comments
 (0)