Skip to content

Commit a4cb74a

Browse files
author
José Valim
committed
Include stracktrace on ExUnit timeouts
Signed-off-by: José Valim <[email protected]>
1 parent bbf9552 commit a4cb74a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,17 @@ defmodule ExUnit.Runner do
220220
%{test | state: {:failed, {{:EXIT, test_pid}, error, []}}}
221221
after
222222
timeout ->
223+
stacktrace =
224+
try do
225+
Process.info(test_pid, :current_stacktrace)
226+
catch
227+
_, _ -> []
228+
else
229+
{:current_stacktrace, stacktrace} -> stacktrace
230+
end
223231
Process.exit(test_pid, :kill)
224232
Process.demonitor(test_ref, [:flush])
225-
%{test | state: {:failed, {:error, %ExUnit.TimeoutError{timeout: timeout}, []}}}
233+
%{test | state: {:failed, {:error, %ExUnit.TimeoutError{timeout: timeout}, stacktrace}}}
226234
end
227235

228236
exec_on_exit(test, test_pid)

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ defmodule ExUnitTest do
5050
end
5151
end
5252

53-
assert capture_io(fn -> ExUnit.run end) =~
54-
"** (ExUnit.TimeoutError) test timed out after 10ms"
53+
output = capture_io(fn -> ExUnit.run end)
54+
assert output =~ "** (ExUnit.TimeoutError) test timed out after 10ms"
55+
assert output =~ ~r"\(stdlib\) timer\.erl:\d+: :timer\.sleep/1"
5556
end
5657

5758
test "filtering cases with tags" do

0 commit comments

Comments
 (0)