Eunit test process killed when unloading module with tests

Jonas Boberg jonas.boberg@REDACTED
Mon Jun 7 14:37:10 CEST 2010


Hi!

We've encountered a rare eunit bug related to test
generators and code loading.

Erlang version: R13B04 (reproduced in R13B03 as well).
OS: Mac OS X 10.5, 10.6, Ubuntu 8.1 (probably all platforms).

How to reproduce (minimal):

* Create two modules: a_mod.erl and b_mod.erl, with the
content as seen below
* In an Erlang shell:
c(a_mod), c(b_mod).
eunit:test([a_mod, b_mod]).
*unexpected termination of test process*
::killed

It seems that after running the a_mod test module, 
eunit leaves a process that is executing inside it 
(or that is what we believe).
This causes the test process to be killed when
the second test runs code:purge(a_mod).

* This only occurs when the module that is unloaded
has a test generator (first_test_ in this example), 
not if it has a 'normal' test function.

Now, you may wonder why anyone would want to do this.
Well, in this minimal example it is not apparent, but
we have white-box unit tests in header files that we
conditionally include in our modules. Sometimes
we mock other modules in the same application, and
then we hit this bug.

a_mod.erl:
-------------------------------------------------
-module(a_mod).

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

first_test_() ->
    {foreach, fun setup/0, fun teardown/1,
     [
      fun first_/0
     ]}.


setup() ->
    ok.

teardown(_) ->
    ok.

first_() ->
    ok.
-------------------------------------------------

b_mod.erl:
----------------------
-module(b_mod).

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

second_test() ->
    code:delete(a_mod),
    code:purge(a_mod),
    ok.
----------------------

---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-bugs mailing list