Skip to content

Commit f83ba18

Browse files
committed
integration: simplify test splitting
Avoid the need to pass slice config with env variable. Instead slice can be set directly in the --run filter. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 21a6d8b commit f83ba18

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

.github/workflows/test-os.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ jobs:
110110
name: Prepare
111111
run: |
112112
TESTPKG=$(echo "${{ matrix.pkg }}" | awk '-F#' '{print $1}')
113-
TESTSLICE=$(echo "${{ matrix.pkg }}" | awk '-F#' '{print $2}')
114113
echo "TESTPKG=$TESTPKG" >> $GITHUB_ENV
115114
echo "TEST_REPORT_NAME=${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.skip-integration-tests }}-${{ matrix.worker }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
116115
testFlags="${{ env.TESTFLAGS }}"
116+
testSlice=$(echo "${{ matrix.pkg }}" | awk '-F#' '{print $2}')
117117
testSliceOffset=""
118-
if [ -n "$TESTSLICE" ]; then
119-
echo "TESTSLICE=$TESTSLICE" >> $GITHUB_ENV
120-
testSliceOffset="slice=$TESTSLICE/"
118+
if [ -n "$testSlice" ]; then
119+
testSliceOffset="slice=$testSlice/"
121120
fi
122121
if [ -n "${{ matrix.worker }}" ]; then
123122
testFlags="${testFlags} --run=TestIntegration/$testSliceOffset.*/worker=${{ matrix.worker }}"

util/testutil/integration/run.go

+29-14
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,26 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) {
164164
}
165165

166166
var sliceSplit int
167-
v, ok := os.LookupEnv("TESTSLICE")
168-
if ok {
169-
t.Logf("TESTSLICE=%s", v)
170-
offsetS, totalS, ok := strings.Cut(v, "-")
171-
if !ok {
172-
t.Fatalf("invalid TESTSLICE=%s", v)
173-
}
174-
offset, err := strconv.Atoi(offsetS)
175-
require.NoError(t, err)
176-
total, err := strconv.Atoi(totalS)
177-
require.NoError(t, err)
178-
if offset < 1 || total < 1 || offset > total {
179-
t.Fatalf("invalid TESTSLICE=%s", v)
167+
if filter, ok := lookupTestFilter(); ok {
168+
parts := strings.Split(filter, "/")
169+
if len(parts) >= 2 {
170+
const prefix = "slice="
171+
if strings.HasPrefix(parts[1], prefix) {
172+
conf := strings.TrimPrefix(parts[1], prefix)
173+
offsetS, totalS, ok := strings.Cut(conf, "-")
174+
if !ok {
175+
t.Fatalf("invalid slice=%q", conf)
176+
}
177+
offset, err := strconv.Atoi(offsetS)
178+
require.NoError(t, err)
179+
total, err := strconv.Atoi(totalS)
180+
require.NoError(t, err)
181+
if offset < 1 || total < 1 || offset > total {
182+
t.Fatalf("invalid slice=%q", conf)
183+
}
184+
sliceSplit = total
185+
}
180186
}
181-
sliceSplit = total
182187
}
183188

184189
var tc testConf
@@ -488,3 +493,13 @@ func UnixOrWindows[T any](unix, windows T) T {
488493
}
489494
return unix
490495
}
496+
497+
func lookupTestFilter() (string, bool) {
498+
const prefix = "-test.run="
499+
for _, arg := range os.Args {
500+
if strings.HasPrefix(arg, prefix) {
501+
return strings.TrimPrefix(arg, prefix), true
502+
}
503+
}
504+
return "", false
505+
}

0 commit comments

Comments
 (0)