[erlang-questions] EUnit and Servers
Fred Hebert
mononcqc@REDACTED
Sun Sep 27 19:46:01 CEST 2009
On Sun, Sep 27, 2009 at 1:28 PM, Jachym Holecek <freza@REDACTED> wrote:
> # 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() ->
> {inorder,
> [?assert(close_enough(box:get_status(),
> get_val(box:init(200)))),
> ?assert(close_enough(begin
> box:get_air(100),
> box:get_status()
> end,
> get_val(box:init(100))))]}
> end}.
>
> 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
> box:stop/0.
>
> 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.
>
> HTH,
> -- Jachym
>
Ah, thank you Richard and Jachym. I switched to the ?_assert() macros, added
an arity of one to the test function (fun(_) -> {inorder, [...]} end).
I then revised the box gen_server: I changed stop/0 from doing a cast to a
call and everything started working fine.
Thanks for the help, much appreciated.
More information about the erlang-questions
mailing list