From ebbb4cf80f687716fb04f1ff317732b59d9af90a Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 3 Jun 2025 13:53:16 +0100 Subject: [PATCH] fix(coverage): add TESTFLAGS support and fix grep typo in scripts/coverage.sh, Enhanced build-test.yml to: - Add flaky test detection step with -shuffle=on -count=5 -v. - Upload test output as an artifact for debugging. Signed-off-by: Victor --- .github/workflows/build-test.yml | 22 +++++++++++++++++++--- scripts/coverage.sh | 7 +++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 11a5c49ec..d545c40ae 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,4 +1,5 @@ -name: build-test +name: Build and Test + on: push: branches: @@ -28,7 +29,22 @@ jobs: check-latest: true - name: Test source headers are present run: make test-source-headers - - name: Run unit tests + - name: Run unit tests with coverage run: make test-coverage + - name: Run unit tests with shuffle for flaky test detection + env: + TESTFLAGS: -shuffle=on -count=5 -v + run: | + ./scripts/coverage.sh | tee test_output.txt + if grep -B 5 "FAIL" test_output.txt; then + echo "Flaky tests detected. Please review test_output.txt for details." + exit 1 + fi + - name: Upload test output for debugging + if: always() + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # pin@v4.4.0 + with: + name: test-output + path: test_output.txt - name: Test build - run: make build + run: make build \ No newline at end of file diff --git a/scripts/coverage.sh b/scripts/coverage.sh index 2164d94da..6659b03b8 100755 --- a/scripts/coverage.sh +++ b/scripts/coverage.sh @@ -21,10 +21,10 @@ coverdir=$(mktemp -d /tmp/coverage.XXXXXXXXXX) profile="${coverdir}/cover.out" generate_cover_data() { - for d in $(go list ./...) ; do + for d in $(go list ./...); do ( local output="${coverdir}/${d//\//-}.cover" - go test -coverprofile="${output}" -covermode="$covermode" "$d" + go test -coverprofile="${output}" -covermode="$covermode" ${TESTFLAGS:-} "$d" ) done @@ -39,5 +39,4 @@ case "${1-}" in --html) go tool cover -html "${profile}" ;; -esac - +esac \ No newline at end of file