chore: retry failing tests in CI (#17681)

This PR introduces failing test retries in CI for e2e tests, Go tests
with the in-memory database, Go tests with Postgres, and the CLI tests.
Retries are not enabled for race tests.

The goal is to reduce how often flakes disrupt developers' workflows.
This commit is contained in:
Hugo Dutka
2025-05-06 16:53:26 +02:00
committed by GitHub
parent d9b00e4849
commit a7e828593f
3 changed files with 35 additions and 5 deletions
+7 -2
View File
@@ -382,8 +382,8 @@ jobs:
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
fi fi
export TS_DEBUG_DISCO=true export TS_DEBUG_DISCO=true
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \ gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" --rerun-fails=2 \
--packages="./..." -- $PARALLEL_FLAG -short -failfast --packages="./..." -- $PARALLEL_FLAG -short
- name: Upload Test Cache - name: Upload Test Cache
uses: ./.github/actions/test-cache/upload uses: ./.github/actions/test-cache/upload
@@ -436,6 +436,7 @@ jobs:
TS_DEBUG_DISCO: "true" TS_DEBUG_DISCO: "true"
LC_CTYPE: "en_US.UTF-8" LC_CTYPE: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8" LC_ALL: "en_US.UTF-8"
TEST_RETRIES: 2
shell: bash shell: bash
run: | run: |
# By default Go will use the number of logical CPUs, which # By default Go will use the number of logical CPUs, which
@@ -499,6 +500,7 @@ jobs:
TS_DEBUG_DISCO: "true" TS_DEBUG_DISCO: "true"
LC_CTYPE: "en_US.UTF-8" LC_CTYPE: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8" LC_ALL: "en_US.UTF-8"
TEST_RETRIES: 2
shell: bash shell: bash
run: | run: |
# By default Go will use the number of logical CPUs, which # By default Go will use the number of logical CPUs, which
@@ -560,6 +562,7 @@ jobs:
env: env:
POSTGRES_VERSION: "16" POSTGRES_VERSION: "16"
TS_DEBUG_DISCO: "true" TS_DEBUG_DISCO: "true"
TEST_RETRIES: 2
run: | run: |
make test-postgres make test-postgres
@@ -784,6 +787,7 @@ jobs:
if: ${{ !matrix.variant.premium }} if: ${{ !matrix.variant.premium }}
env: env:
DEBUG: pw:api DEBUG: pw:api
CODER_E2E_TEST_RETRIES: 2
working-directory: site working-directory: site
# Run all of the tests with a premium license # Run all of the tests with a premium license
@@ -793,6 +797,7 @@ jobs:
DEBUG: pw:api DEBUG: pw:api
CODER_E2E_LICENSE: ${{ secrets.CODER_E2E_LICENSE }} CODER_E2E_LICENSE: ${{ secrets.CODER_E2E_LICENSE }}
CODER_E2E_REQUIRE_PREMIUM_TESTS: "1" CODER_E2E_REQUIRE_PREMIUM_TESTS: "1"
CODER_E2E_TEST_RETRIES: 2
working-directory: site working-directory: site
- name: Upload Playwright Failed Tests - name: Upload Playwright Failed Tests
+10 -3
View File
@@ -875,12 +875,19 @@ provisioner/terraform/testdata/version:
fi fi
.PHONY: provisioner/terraform/testdata/version .PHONY: provisioner/terraform/testdata/version
# Set the retry flags if TEST_RETRIES is set
ifdef TEST_RETRIES
GOTESTSUM_RETRY_FLAGS := --rerun-fails=$(TEST_RETRIES)
else
GOTESTSUM_RETRY_FLAGS :=
endif
test: test:
$(GIT_FLAGS) gotestsum --format standard-quiet -- -v -short -count=1 ./... $(if $(RUN),-run $(RUN)) $(GIT_FLAGS) gotestsum --format standard-quiet $(GOTESTSUM_RETRY_FLAGS) --packages="./..." -- -v -short -count=1 $(if $(RUN),-run $(RUN))
.PHONY: test .PHONY: test
test-cli: test-cli:
$(GIT_FLAGS) gotestsum --format standard-quiet -- -v -short -count=1 ./cli/... $(GIT_FLAGS) gotestsum --format standard-quiet $(GOTESTSUM_RETRY_FLAGS) --packages="./cli/..." -- -v -short -count=1
.PHONY: test-cli .PHONY: test-cli
# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a # sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
@@ -919,9 +926,9 @@ test-postgres: test-postgres-docker
$(GIT_FLAGS) DB=ci gotestsum \ $(GIT_FLAGS) DB=ci gotestsum \
--junitfile="gotests.xml" \ --junitfile="gotests.xml" \
--jsonfile="gotests.json" \ --jsonfile="gotests.json" \
$(GOTESTSUM_RETRY_FLAGS) \
--packages="./..." -- \ --packages="./..." -- \
-timeout=20m \ -timeout=20m \
-failfast \
-count=1 -count=1
.PHONY: test-postgres .PHONY: test-postgres
+18
View File
@@ -10,12 +10,30 @@ import {
} from "./constants"; } from "./constants";
export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT; export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT;
export const retries = (() => {
if (process.env.CODER_E2E_TEST_RETRIES === undefined) {
return undefined;
}
const count = Number.parseInt(process.env.CODER_E2E_TEST_RETRIES, 10);
if (Number.isNaN(count)) {
throw new Error(
`CODER_E2E_TEST_RETRIES is not a number: ${process.env.CODER_E2E_TEST_RETRIES}`,
);
}
if (count < 0) {
throw new Error(
`CODER_E2E_TEST_RETRIES is less than 0: ${process.env.CODER_E2E_TEST_RETRIES}`,
);
}
return count;
})();
const localURL = (port: number, path: string): string => { const localURL = (port: number, path: string): string => {
return `http://localhost:${port}${path}`; return `http://localhost:${port}${path}`;
}; };
export default defineConfig({ export default defineConfig({
retries,
globalSetup: require.resolve("./setup/preflight"), globalSetup: require.resolve("./setup/preflight"),
projects: [ projects: [
{ {