Skip to content

Commit bf6aaa5

Browse files
committed
github: stress new unit tests in PRs
This commit adds a script that detects any new top-level unit tests and runs them under stress; and adds a corresponding CI job that only runs on PRs. Fixes #5038
1 parent ffd01fd commit bf6aaa5

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,24 @@ jobs:
102102

103103
- run: GOTRACEBACK=all make test
104104

105+
stress-new-tests:
106+
if: github.event_name == 'pull_request' # Skip job unless it's a PR
107+
runs-on: ubuntu-latest
108+
109+
steps:
110+
- name: Checkout code
111+
uses: actions/checkout@v4
112+
with:
113+
fetch-depth: 0
114+
115+
- name: Set up Go
116+
uses: actions/setup-go@v5
117+
with:
118+
go-version: '1.24'
119+
120+
- name: Stress new tests
121+
env:
122+
BASE_BRANCH: origin/${{ github.base_ref }}
123+
run: |
124+
go install github.com/cockroachdb/stress@latest
125+
bash scripts/stress-new-tests.sh

scripts/stress-new-tests.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Base branch to diff against
5+
BASE_BRANCH="${BASE_BRANCH:-origin/master}"
6+
MODULE_PREFIX="github.com/cockroachdb/pebble"
7+
8+
# Loop through each Go package
9+
echo "Checking packages for new tests..."
10+
for pkg in $(go list ./...); do
11+
# Strip module prefix to get relative path
12+
pkg=${pkg#${MODULE_PREFIX}}
13+
pkg="./${pkg#/}" # Ensure ./ and remove any leading /
14+
15+
# Get added test functions in this package
16+
added_tests=$(git diff --no-ext-diff "$BASE_BRANCH" --unified=0 -- "$pkg"/*.go 2>/dev/null \
17+
| grep '^+func Test' \
18+
| awk '{print $2}' \
19+
| cut -d'(' -f1 \
20+
| sort -u || true)
21+
22+
if [[ -z "$added_tests" ]]; then
23+
continue
24+
fi
25+
26+
# Build regex for go test -run
27+
regex=$(echo "$added_tests" | paste -sd '|' -)
28+
full_regex="^($regex)$"
29+
30+
echo ""
31+
echo "Found new tests in $pkg"
32+
33+
echo "go test --tags invariants --exec 'stress -p 2 --maxruns 1000 --maxtime 10m --timeout 2m' -v -run \"$full_regex\" \"$pkg\""
34+
go test --tags invariants --exec 'stress -p 2 --maxruns 1000 --maxtime 10m --timeout 2m' -v -run "$full_regex" "$pkg" || {
35+
echo ""
36+
echo "❌ Failure in $pkg with new tests: $regex"
37+
exit 1
38+
}
39+
done
40+
41+
echo "✅ All stress tests passed."

0 commit comments

Comments
 (0)