[erlang-questions] common_test vs supervised process

Siri Hansen <>
Tue Jul 3 11:27:08 CEST 2012


It's a while since you wrote this, so you might have come to some
conclusion by now, but anyway - here's what happens:

Since your top supervisor is started with start_link, it will be linked to
the test case process. The test case process does not trap exit. When
stopping your service, the supervisor is terminated with reason shutdown.
Due to the link and not trapping exits, the test case process will also
terminate with reason shutdown and thus common_test believes that the test
has failed with this reason. After all, a terminating test case process is
the definition of a failed test case in common_test world.

Regards
/siri


2012/6/21 Attila Rajmund Nohl <>

> Hello!
>
> I try to test our code with common_test (from the OTP master branch).
> This code starts a supervisor, which starts a process. For some reason
> the test fails with:
>
> *** CT Error Notification 2012-06-21 19:38:59.236 ***
> Error detected: shutdown
>
> even though the started process doesn't crash (or at least I don't see
> it). I'm probably making something really stupid, do you have any idea
> what?
>
> Here's the important part of the code. The testcase (the init_*
> functions are empty):
>
> start_stop_test(_Config) ->
>     {ok, Pid} = inets:start(ftpd, [{port, 2021}]),
>     inets:stop(ftpd, Pid).
>
> The ftpd module:
>
> start_service(Config) ->
>     ftpd_sup:start_link(Config).
>
> stop_service(Pid) when is_pid(Pid) ->
>    case ftpd_sup:stop(Pid) of
>         true -> ok;
>         R -> { error, R }
>    end.
>
> The ftpd_sup module:
>
> start_link(Args) ->
>     supervisor:start_link(ftpd_sup, Args).
>
> stop(Pid) ->
>         exit(Pid,shutdown),
>         true.
>
> init(Args) ->
>         NewArgs = [ {sup_pid, self()} | Args],
>         {ok, {{one_for_one, 10, 60},
>           [{ftpd_listener,
>            {ftpd_listener, start_link, [NewArgs]},
>            permanent,
>            brutal_kill,
>            worker,
>            [ftpd_listener]}]}}.
>
> And the ftpd_listener:
>
> start_link(Args) ->
>     proc_lib:start_link(?MODULE, listener_init, [self(), Args]).
>
> listener_init(Parent, Args) ->
>     proc_lib:init_ack(Parent, {ok, self()}),
>     Port = proplists:get_value(port,Args),
>     SupPid = proplists:get_value(sup_pid,Args),
>     {ok, LSock} = gen_tcp:listen(Port, [binary, {packet, 0}, {active,
> false}]),
>     loop(LSock, SupPid).
>
> loop(LSock, SupPid) ->
>         case gen_tcp:accept(LSock) of
>                 {ok, Sock} ->
>                     loop(LSock, SupPid);
>                 {_, Res} -> ok
>         end.
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120703/2f31b694/attachment.html>


More information about the erlang-questions mailing list