Skip to content

Commit 5b97e9c

Browse files
authored
Show remaining runs when using --repeat-until-failure (#15270)
The --repeat-until-failure can be very useful for finding flaky tests, however sometimes it is hard to gauge how long it has left to run before it can be considered successful. This commit adds a small output showing the number of remaining runs when the `--repeat-until-failure` flag is used. It looks like: ``` Running ExUnit with seed: 382462, max_cases: 32, remaining_runs: 3 Excluding tags: [windows: true] ....... Finished in 0.02 seconds (0.00s async, 0.02s sync) Result: 7 passed Running ExUnit with seed: 422319, max_cases: 32, remaining_runs: 2 Excluding tags: [windows: true] ....... Finished in 0.00 seconds (0.00s async, 0.00s sync) ```
1 parent 8ba8ad7 commit 5b97e9c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/ex_unit/lib/ex_unit.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ defmodule ExUnit do
570570
end
571571

572572
defp maybe_repeated_run(options, seed, load_us, repeat) do
573+
options = Keyword.put(options, :remaining_runs, repeat)
574+
573575
case ExUnit.Runner.run(options, load_us) do
574576
{%{failures: 0}, {async_modules, sync_modules}}
575577
when repeat > 0 and (sync_modules != [] or async_modules != []) ->

lib/ex_unit/lib/ex_unit/cli_formatter.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ defmodule ExUnit.CLIFormatter do
1212
## Callbacks
1313

1414
def init(opts) do
15-
IO.puts("Running ExUnit with seed: #{opts[:seed]}, max_cases: #{opts[:max_cases]}")
15+
remaining =
16+
if opts[:repeat_until_failure] > 0 do
17+
", remaining_runs: #{opts[:remaining_runs]}"
18+
else
19+
""
20+
end
21+
22+
IO.puts([
23+
"Running ExUnit with seed: #{opts[:seed]}, max_cases: #{opts[:max_cases]}",
24+
remaining
25+
])
26+
1627
print_filters(opts, :exclude)
1728
print_filters(opts, :include)
1829
IO.puts("")

lib/ex_unit/test/ex_unit_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ defmodule ExUnitTest do
10211021
runs = String.split(output, "Running ExUnit", trim: true)
10221022
# 6 runs in total, 5 repeats
10231023
assert length(runs) == 6
1024+
assert output =~ "remaining_runs: 5"
1025+
assert output =~ "remaining_runs: 0"
10241026
end
10251027

10261028
test "repeats tests up to the configured number of times with groups" do
@@ -1039,6 +1041,8 @@ defmodule ExUnitTest do
10391041
runs = String.split(output, "Running ExUnit", trim: true)
10401042
# 6 runs in total, 5 repeats
10411043
assert length(runs) == 6
1044+
assert output =~ "remaining_runs: 5"
1045+
assert output =~ "remaining_runs: 0"
10421046
end
10431047

10441048
test "stops on failure" do
@@ -1080,6 +1084,7 @@ defmodule ExUnitTest do
10801084
# four runs in total, the first two repeats work fine, the third repeat (4th run)
10811085
# fails, therefore we stop
10821086
assert length(runs) == 4
1087+
assert output =~ "remaining_runs: 2"
10831088
assert List.last(runs) =~ "Expected truthy, got false"
10841089
end
10851090
end

0 commit comments

Comments
 (0)