commit: ed2976b237b53a524247d564691e0a12d3231d68
parent 3a8420b141c5186a02be702b59a3799ff65cf4f8
Author: Mark Felder <feld@feld.me>
Date: Wed, 19 Jun 2024 19:04:09 -0400
Custom mix task to retry failed tests once in CI pipeline
This will be temporary* as we hunt down the cause of the random test failures
* gonna regret this
Diffstat:
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
@@ -135,7 +135,7 @@ unit-testing-1.13.4-otp-25:
script: &testing_script
- mix ecto.create
- mix ecto.migrate
- - mix test --cover --preload-modules
+ - mix pleroma.test_runner --cover --preload-modules
coverage: '/^Line total: ([^ ]*%)$/'
artifacts:
reports:
@@ -165,7 +165,7 @@ unit-testing-1.13.4-otp-25-erratic:
script:
- mix ecto.create
- mix ecto.migrate
- - mix test --only=erratic
+ - mix pleroma.test_runner --only=erratic
formatting-1.15:
extends: .build_changes_policy
diff --git a/lib/mix/tasks/pleroma/test_runner.ex b/lib/mix/tasks/pleroma/test_runner.ex
@@ -0,0 +1,25 @@
+defmodule Mix.Tasks.Pleroma.TestRunner do
+ @shortdoc "Retries tests once if they fail"
+
+ use Mix.Task
+
+ def run(args \\ []) do
+ case System.cmd("mix", ["test"] ++ args, into: IO.stream(:stdio, :line)) do
+ {_, 0} ->
+ :ok
+
+ _ ->
+ retry(args)
+ end
+ end
+
+ def retry(args) do
+ case System.cmd("mix", ["test", "--failed"] ++ args, into: IO.stream(:stdio, :line)) do
+ {_, 0} ->
+ :ok
+
+ _ ->
+ exit(1)
+ end
+ end
+end