[erlang-questions] Idly wondering why this code in common test suite, init_per_suite/1 works

bengt cean.ebengt@REDACTED
Tue Jul 3 20:52:10 CEST 2018


Greetings,

If somebody happens to know, otherwise ignore. I can read the source myself.

1) If I use start_link() from my test suites init_per_suite/1,then the gen_server is dead in the test cases.

2) This made me either use gen_server:start(), or if the coding guidelines insist upon placing the start_link() inside the gen_server callback module, the following:

init_per_suite(Config) ->
P = erlang:spawn( fun() ->
        {ok, _} = mm:start_link(),
	receive
	end_per_suite -> ok
	end
end ),
[{mm_pid, P} | Config].

In end_per_suite/1 I then send end_per_suite to Pid and the process exits. Probably taking the gen_server with it. Unless it is trapping exists etc… But this one is not.

Today I forgot the receive statement . Like this:

init_per_suite(Config) ->
P = erlang:spawn( fun() ->
        {ok, _} = mm:start_link( ),
end ),
[{mm_pid, P}|Config].

And it still worked. Why?
Is this not the same thing when the spawned fun returns, as when init_per_suite/1 returned without spawning (in 1)?


Surprised,
bengt


More information about the erlang-questions mailing list