[erlang-questions] common_test vs supervised process

Attila Rajmund Nohl attila.r.nohl@REDACTED
Thu Jun 21 19:51:24 CEST 2012


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.



More information about the erlang-questions mailing list