From 0e7c557a9909f531530ee4742eb04ce23f03e3d6 Mon Sep 17 00:00:00 2001 From: Klas Johansson Date: Sun, 17 Apr 2011 22:05:43 +0200 Subject: Wait until all eunit listeners terminate Ensure that all eunit listeners (like eunit_surefire) get the chance to finish their work before terminating. Prior to this fix, the eunit_surefire XML was sometimes not generated. --- lib/eunit/src/eunit.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/eunit') diff --git a/lib/eunit/src/eunit.erl b/lib/eunit/src/eunit.erl index 4a86a108cf..da35c5c2ec 100644 --- a/lib/eunit/src/eunit.erl +++ b/lib/eunit/src/eunit.erl @@ -157,6 +157,7 @@ test_run(Reference, Listeners) -> receive {done, Reference} -> cast(Listeners, {stop, Reference, self()}), + wait_until_listeners_have_terminated(Listeners), receive {result, Reference, Result} -> Result @@ -169,6 +170,15 @@ cast([P | Ps], Msg) -> cast([], _Msg) -> ok. +wait_until_listeners_have_terminated([P | Ps]) -> + MRef = erlang:monitor(process, P), + receive + {'DOWN', MRef, process, P, _} -> + wait_until_listeners_have_terminated(Ps) + end; +wait_until_listeners_have_terminated([]) -> + ok. + %% TODO: functions that run tests on a given node, not a given server %% TODO: maybe some functions could check for a globally registered server? %% TODO: some synchronous but completely quiet interface function -- cgit v1.2.3 From bd38a126546376246f9a93a2943e70a3925df48f Mon Sep 17 00:00:00 2001 From: Klas Johansson Date: Sun, 17 Apr 2011 22:26:43 +0200 Subject: Don't let eunit_surefire report back to eunit when stopping When eunit is terminating, a stop message is sent to all listeners and eunit then waits for *one* result message but previously both eunit_tty and eunit_surefire sent a response on error. Don't send a result message from eunit_surefire; let eunit_tty take care of all result reporting, both positive and negative to avoid race conditions and inconsistencies. --- lib/eunit/src/eunit_surefire.erl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'lib/eunit') diff --git a/lib/eunit/src/eunit_surefire.erl b/lib/eunit/src/eunit_surefire.erl index f289cd724a..dfb08c90b2 100644 --- a/lib/eunit/src/eunit_surefire.erl +++ b/lib/eunit/src/eunit_surefire.erl @@ -100,16 +100,10 @@ terminate({ok, _Data}, St) -> XmlDir = St#state.xmldir, write_report(TestSuite, XmlDir), ok; -terminate({error, Reason}, _St) -> - io:fwrite("Internal error: ~P.\n", [Reason, 25]), - sync_end(error). - -sync_end(Result) -> - receive - {stop, Reference, ReplyTo} -> - ReplyTo ! {result, Reference, Result}, - ok - end. +terminate({error, _Reason}, _St) -> + %% Don't report any errors here, since eunit_tty takes care of that. + %% Just terminate. + ok. handle_begin(group, Data, St) -> NewId = proplists:get_value(id, Data), -- cgit v1.2.3