views:

91

answers:

1

Hi, I am trying to run all unit tests using eunit inside a folder but it seems like timeout always reset to 5 seconds.

e.g.

Module:

-module(example).
-include_lib("eunit/include/eunit.hrl").

main_test() ->
    % sleep for 10 seconds
    ?assertEqual(true, begin timer:sleep(10000), true end).

Command line:

Eshell V5.7.3  (abort with ^G)
1> c(example).
{ok,example}
2> eunit:test({timeout, 15, example}).
  Test passed.
ok
3> eunit:test({timeout, 15, {dir, "."}}).
example: main_test (module 'example')...*timed out*
undefined
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error

As you can see, running {timeout, 15, example} works but not {timeout, 15, {dir, "."}}. Dose anyone have a clue?

+2  A: 

To me that makes sense: the timeout for an entire directory is probably not related to the timeouts for the individual tests.

I would write the test like this:

main_test_() ->
    % sleep for 10 seconds
    {timeout, 15, ?_assertEqual(true, begin timer:sleep(10000), true end)}.

(Underscores added to create a test expression instead of the test itself; it's all in the eunit manual. I don't think it's possible to specify a timeout in the test itself in any other way.)

legoscia