From cd89ccdb4003847e26716be99f70f98dec1ca6a3 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 17 Nov 2026 16:24:09 +0800 Subject: [PATCH] ci: macOS tests in four parts at once (#6903) macOS ran everything in one job on a 3-core runner: ~93 minutes on 44024695993 (Test 65m, Race 24m), and the Test step met its 75m cap with no test failing (#6903). The packages' own times sum to ~2250s; the rest was waiting for a processor. Raising the cap would only be met again. macOS now runs as four jobs: three shares of the packages but the gateway (build/pkg-shards.sh, slowest first onto the lightest share, with macOS CI's seconds for the slow packages), and the gateway with the race steps. The old Test step is split into Test (packages) and Gateway; ubuntu and Windows run whole as before. Vet runs once on macOS, in share 1/3. The Test cap goes from 75 to 45 minutes. Run: build/pkg-shards.sh 1..3 of 3 over `go list ./...` (124 packages): 41/42/41, each with three of the slow packages, ~870s apiece, and their union is the list; the step's pipeline under bash -eo pipefail (bash 3.2 too) for each part; actionlint (only the Gofmt step's old SC2046). workflow_dispatch run 44046493476 at this tree (branch ci-mac-parts), all green: macOS 1/3 12m, 2/3 17m, 3/3 15m, gateway with race 34m (the macOS job was ~93m); ubuntu 37m, windows 5m. --- .github/workflows/test.yml | 50 +++++++++++++++++++++++++++----------- build/pkg-shards.sh | 34 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 14 deletions(-) create mode 100755 build/pkg-shards.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 010b00e1e..bae2cfa32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,11 +18,22 @@ permissions: jobs: test: - name: test (${{ matrix.os }}) + name: test (${{ matrix.os }}${{ matrix.part && format(', {0}', matrix.part) || '' }}) strategy: fail-fast: false + # macOS runs in four parts at once: the packages but the gateway in + # three shares (build/pkg-shards.sh), and the gateway with the race + # steps. In one job it took ~93 minutes on a 3-core runner, and its + # Test step met the 75m cap with no test failing (#6903): the cap was + # set when that step took 31. Ubuntu and Windows run whole. matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + include: + - os: ubuntu-latest + - os: windows-latest + - {os: macos-latest, part: '1/3'} + - {os: macos-latest, part: '2/3'} + - {os: macos-latest, part: '3/3'} + - {os: macos-latest, part: gateway} runs-on: ${{ matrix.os }} steps: @@ -59,29 +70,40 @@ jobs: if [ -n "$bad" ]; then echo "not gofmt'd:"; echo "$bad"; exit 1; fi - name: Vet + if: matrix.part == '' || matrix.part == '1/3' run: go vet -tags "${{ steps.tags.outputs.tags }}" ./... - uses: oven-sh/setup-bun@v2 with: bun-version: 1.4.2 + # A step cap: on 0dbdc7481's macOS run internal/library printed + # nothing for 44 minutes past go test's own -timeout 30m (no panic, no + # stack, #5267), and main's later runs queued behind it until it was + # cancelled by hand. A share of macOS's packages takes ~20 minutes, and + # ubuntu's whole run ~11. + - name: Test + if: runner.os != 'Windows' && matrix.part != 'gateway' + timeout-minutes: 45 + shell: bash + env: + PART: ${{ matrix.part }} + run: | + go list -tags "${{ steps.tags.outputs.tags }}" ./... | grep -v '/internal/gateway$' | + if [ -n "$PART" ]; then build/pkg-shards.sh "${PART%/*}" "${PART#*/}"; else cat; fi | + xargs go test -timeout 30m -tags "${{ steps.tags.outputs.tags }}" + # internal/gateway's tests run one at a time (t.Setenv rules out # t.Parallel): 892s on mote for 4286 tests on 11-15, none over 20s, # 965s on macOS CI, and past the 30m alarm on f1c9014cd with no test # hung (#2191). It grew from 450-600s on 10-28, so a longer timeout # would only be met again. Its plain run goes in chunks, one process - # per core, as the Race step's does; the other packages run as before. - # A step cap as well: on 0dbdc7481's macOS run internal/library printed - # nothing for 44 minutes past go test's own -timeout 30m (no panic, no - # stack, #5267), and main's later runs queued behind it until it was - # cancelled by hand. Test took 11 minutes on ubuntu there and 31 on - # macOS the run before; the cap leaves room for a slow macOS runner. - - name: Test - if: runner.os != 'Windows' - timeout-minutes: 75 + # per core, as the Race step's does. + - name: Gateway + if: runner.os != 'Windows' && (matrix.part == '' || matrix.part == 'gateway') + timeout-minutes: 30 shell: bash run: | - go test -timeout 30m -tags "${{ steps.tags.outputs.tags }}" $(go list -tags "${{ steps.tags.outputs.tags }}" ./... | grep -v '/internal/gateway$') go test -c -o "$RUNNER_TEMP/gateway.test" -tags "${{ steps.tags.outputs.tags }}" ./internal/gateway/ build/race-shards.sh internal/gateway "$RUNNER_TEMP/gateway.test" "$(getconf _NPROCESSORS_ONLN)" -test.timeout=20m @@ -109,7 +131,7 @@ jobs: # one process per core at a time, each taking the next chunk when done # (#923, #5361); each process isolates its own home. - name: Race - if: runner.os != 'Windows' + if: runner.os != 'Windows' && (matrix.part == '' || matrix.part == 'gateway') shell: bash run: | go test -race -c -o "$RUNNER_TEMP/gateway.race" -tags "${{ steps.tags.outputs.tags }}" ./internal/gateway/ @@ -118,7 +140,7 @@ jobs: # Account usage mixes cached results with concurrent fetches. - name: Race account usage - if: runner.os != 'Windows' + if: runner.os != 'Windows' && (matrix.part == '' || matrix.part == 'gateway') run: go test -race -tags "${{ steps.tags.outputs.tags }}" ./internal/provider/ -run '^Test(LoginUsage|SubscriptionUsageEachAccount)' # Some tests fake a home through $HOME, which Windows doesn't read diff --git a/build/pkg-shards.sh b/build/pkg-shards.sh new file mode 100755 index 000000000..27c2ff708 --- /dev/null +++ b/build/pkg-shards.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# pkg-shards.sh I N: reads import paths on stdin and prints the ones that go +# in share I (1..N) of N, so N runners can test them at once. macOS CI ran +# every package but the gateway in one step on a 3-core runner: ~2250s of +# package time took ~58 minutes of wall time, and the job reached its cap +# with no test failing (#6903). +# +# Each package goes to the share with the least time so far, the slowest +# first (longest processing time first). The seconds below are macOS CI's +# for the slow packages (run 44024695993, 11-17); any other package counts +# as 5s. A stale number only makes the shares less even: every package +# still lands in exactly one share, since every share computes the same +# split. +set -euo pipefail +i=$1 n=$2 +awk -v want="$i" -v n="$n" ' +BEGIN { + split("library 338 gui 261 usage 261 plugin 239 agent 217 provider 204 claudetui 180 davsync 108 sessions 89 cli 76 redact 57 update 34", w, " ") + for (k = 1; k in w; k += 2) secs["github.com/yetone/magpie/internal/" w[k]] = w[k + 1] +} +NF { p[++m] = $1; t[m] = ($1 in secs) ? secs[$1] : 5 } +END { + if (want < 1 || want > n) { print "share " want " of " n "?" > "/dev/stderr"; exit 2 } + # slowest first; ties by name, so every share sorts the same way + for (a = 2; a <= m; a++) for (b = a; b > 1 && (t[b] > t[b-1] || (t[b] == t[b-1] && p[b] < p[b-1])); b--) { + x = p[b]; p[b] = p[b-1]; p[b-1] = x; x = t[b]; t[b] = t[b-1]; t[b-1] = x + } + for (k = 1; k <= m; k++) { + best = 1 + for (s = 2; s <= n; s++) if (load[s] < load[best]) best = s + load[best] += t[k] + if (best == want) print p[k] + } +}'