[erlang-questions] EUnit and Servers

Jachym Holecek freza@REDACTED
Sun Sep 27 19:28:26 CEST 2009

# Fred Hebert (MononcQc) 2009-09-27:
> I have used EUnit before, but rarely did server testing with it. I decided
> to give it a hand with some toy code of mine, but I'm getting errors I'm not
> able to understand the cause of. I'm not willing to blame the tools (eunit)
> before the tool (me), so I'm asking for help here:
> Here's a paste of the test module:
> http://paste.lisp.org/display/87803

    status_test_() ->
        {setup, fun() -> box:start_link(200) end, fun(_) -> box:stop() end,
         fun() ->

I think that you need one of the following (in all the tests you pasted):

  (1) Make the test function have arity one (not zero) and use ?_assert()
      as Kevin points out. This is probably the right thing to do.

  (2) Keep the test function of arity zero, but change the body to simply
      the two ?assert()s executed in a row. This is probably less right.

Now, (2) is equivalent to what you have now, execution-wise, which makes
me suspect there's something wrong with either box:start_link/1 or

Wild speculation: does box:stop/0 guarantee the server is stone dead by
the time it returns? Because if not, the box server could live a little
while longer, making box:start_link/1 in the next test silently fail,
and dying right afterwards, making box:get_status/0 explode.

And one perhaps obvious note: making stop() into a synchronous call is
not good enough -- the thing isn't dead unless you've seen corresponding
'EXIT' or 'DOWN' message.

	-- Jachym

More information about the erlang-questions mailing list