Skip to content

Commit 46e5183

Browse files
committed
Add global LIMA_BATS_ALL_TESTS_RETRIES variable
It will rerun all tests up to this number on failure. Also provides a `flaky` function to set the retries to LIMA_BATS_FLAKY_TESTS_RETRIES to allow a greater number of retries to known flaky tests. Signed-off-by: Jan Dubois <jan.dubois@suse.com>
1 parent f9ab640 commit 46e5183

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hack/bats/helpers/load.bash

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ set -o errexit -o nounset -o pipefail
88
# The upstream PR https://github.com/bats-core/bats-core/pull/1118 is still open, so our submodule points to the PR commit.
99
export BATS_RUN_ERREXIT=1
1010

11+
# BATS_TEST_RETRIES must be set for the individual test and cannot be imported from the
12+
# parent environment because the BATS test runner sets it to 0 before running the test.
13+
BATS_TEST_RETRIES=${LIMA_BATS_ALL_TESTS_RETRIES:-0}
14+
15+
# Known flaky tests should call `flaky` inside the @test to allow retries up to
16+
# LIMA_BATS_FLAKY_TESTS_RETRIES even when the LIMA_BATS_ALL_TESTS_RETRIES is lower.
17+
flaky() {
18+
BATS_TEST_RETRIES=${LIMA_BATS_FLAKY_TESTS_RETRIES:-$BATS_TEST_RETRIES}
19+
}
20+
1121
# Don't run the tests in ~/.lima because they may destroy _config, _templates etc.
1222
export LIMA_HOME=${LIMA_BATS_LIMA_HOME:-$HOME/.lima-bats}
1323

@@ -70,4 +80,4 @@ assert_output_lines_count() {
7080
# NOTE: keep this list in sync with hack/test-templates.sh .
7181
declare -A -g TEST_CONTAINER_IMAGES=(
7282
["nginx"]="ghcr.io/stargz-containers/nginx:1.19-alpine-org"
73-
)
83+
)

0 commit comments

Comments
 (0)