Skip to content

Commit e9887a7

Browse files
author
José Valim
committed
Wait until test process is down in ExUnit runner
This should fix a race condition where the next test would start before all linked processes in the previous test were killed, often leading to already registered errors.
1 parent 0559fe5 commit e9887a7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ defmodule ExUnit.Runner do
159159
{test_case, pending} =
160160
receive do
161161
{^case_pid, :case_finished, test_case, tests} ->
162-
Process.demonitor(case_ref, [:flush])
162+
receive do
163+
{:DOWN, ^case_ref, :process, ^case_pid, _} -> :ok
164+
end
163165
{test_case, tests}
164166
{:DOWN, ^case_ref, :process, ^case_pid, error} ->
165167
test_case = %{test_case | state: {:failed, {{:EXIT, case_pid}, error, []}}}
@@ -214,7 +216,9 @@ defmodule ExUnit.Runner do
214216
test =
215217
receive do
216218
{^test_pid, :test_finished, test} ->
217-
Process.demonitor(test_ref, [:flush])
219+
receive do
220+
{:DOWN, ^test_ref, :process, ^test_pid, _} -> :ok
221+
end
218222
test
219223
{:DOWN, ^test_ref, :process, ^test_pid, error} ->
220224
%{test | state: {:failed, {{:EXIT, test_pid}, error, []}}}

0 commit comments

Comments
 (0)