CI: split heavy packages by test name; one parallel step of 23 shards
Measured on a 32 CPU hosted machine, cold: the headless package ran 301 s
in one shard and set the job's time; lint ran 75 s before any test
started, because steps run one after another and only shards side by
side.
- A lane may now name tests ("TestX", "TestX/subtest" or a regular
expression) of one package. A lane of the same package that names none
runs everything the others do not, so a new test always lands
somewhere. headless is five lanes, runner and directlive three each,
thintest two, equipotest and plan3test one each.
- The quarantine, runner-host and the four static check groups are
shards of the same step, 20-check@23.
- runner-host skips quarantined tests; the quarantine shard beside it
runs them with their retry (TestCheckSandboxDeniedPathsTampering
flaked there once on hosted).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
6 files changed,
+116
−81
.amadan/ci.d/10-lint@4+0 −5.amadan/ci.d/20-check@23+10 −0.amadan/ci.d/30-test@9+0 −8Makefile+6 −18internal/equipotest/foundation_test.go+13 −23scripts/ci-test.py+87 −27
Intent
diff --git a/.amadan/ci.d/10-lint@4 b/.amadan/ci.d/10-lint@4| deleted file mode 100755 |
| index 876f037f..00000000 |
| --- a/.amadan/ci.d/10-lint@4 |
| +++ /dev/null |
| @@ -1,5 +0,0 @@ |
| -#!/bin/sh |
| -# The static checks, four shards side by side (Makefile LINT_SHARD_0 to |
| -# LINT_SHARD_3): build, vet, format, budgets and the migration check; |
| -# staticcheck; govulncheck; gitleaks. AMADAN_SHARD picks one. |
| -exec "$(dirname "$0")/../../scripts/ci-box.py" run make lint-shard |
diff --git a/.amadan/ci.d/20-check@23 b/.amadan/ci.d/20-check@23| new file mode 100755 |
| index 00000000..b6bf1000 |
| --- /dev/null |
| +++ b/.amadan/ci.d/20-check@23 |
| @@ -0,0 +1,10 @@ |
| +#!/bin/sh |
| +# Everything but perf, as 23 shards side by side; AMADAN_SHARD picks one |
| +# (scripts/ci-test.py: LANES, then EXTRA_SHARDS). Seventeen test lanes of |
| +# about a minute each. Then the quarantine: known flaky tests |
| +# (scripts/ci-quarantine.txt), each retried once on failure, a pass on the |
| +# retry reported as a flake. Then runner-host: the exact bubblewrap build, |
| +# the pinned programs, real namespaces and the cgroup move, uncached. Then |
| +# the static checks: build, vet, format, budgets, references and the |
| +# migration check; staticcheck; govulncheck; gitleaks. |
| +exec "$(dirname "$0")/../../scripts/ci-box.py" run make ci-shard |
diff --git a/.amadan/ci.d/30-test@9 b/.amadan/ci.d/30-test@9| deleted file mode 100755 |
| index 53cf1833..00000000 |
| --- a/.amadan/ci.d/30-test@9 |
| +++ /dev/null |
| @@ -1,8 +0,0 @@ |
| -#!/bin/sh |
| -# Nine shards run side by side; AMADAN_SHARD picks one. The first seven |
| -# are the test lanes (scripts/ci-test.py LANES). Then the quarantine: |
| -# known flaky tests (scripts/ci-quarantine.txt), each retried once on |
| -# failure, a pass on the retry reported as a flake. Last, runner-host: |
| -# the exact bubblewrap build, the pinned programs, real namespaces and |
| -# the cgroup move, uncached. |
| -exec "$(dirname "$0")/../../scripts/ci-box.py" run make test-shard |
diff --git a/Makefile b/Makefile| index 5ce970ad..f1e03c8f 100644 |
| --- a/Makefile |
| +++ b/Makefile |
| @@ -27,7 +27,7 @@ RUNNER_RELEASE_DIR = releases/equipo-runner-linux-amd64-$(RELEASE_VERSION) |
| # and a suite running beside it would be measured too. |
| .NOTPARALLEL: |
| -.PHONY: build release test test-lane test-shard test-quarantine vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check runner-adapter-test runner-namespace-test runner-host runner-dead-references lint-shard ci |
| +.PHONY: build release test test-lane ci-shard test-quarantine vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check runner-adapter-test runner-namespace-test runner-host runner-dead-references ci |
| RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo |
| @@ -83,9 +83,10 @@ budget: |
| # lists the packages that must run every time (UNCACHED). |
| # |
| # test runs every package at once. CI runs the same packages as lanes, |
| -# shards of .amadan/ci.d/30-test@9: the slow packages each in a lane of |
| -# their own, side by side (make test-lane LANE=headless runs one), with |
| -# test-quarantine and runner-host as the last two shards. |
| +# shards of .amadan/ci.d/20-check@N side by side: the slow packages split |
| +# by test name into lanes of about a minute (make test-lane |
| +# LANE=headless-work runs one; scripts/ci-test.py lanes lists them), with |
| +# test-quarantine, runner-host and the static checks as further shards. |
| # Known flaky tests are quarantined (scripts/ci-quarantine.txt): skipped |
| # here, run by test-quarantine with one retry, and reported as flakes. |
| test: |
| @@ -94,7 +95,7 @@ test: |
| test-lane: |
| RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py lane $(LANE) |
| -test-shard: |
| +ci-shard: |
| RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py shard |
| test-quarantine: |
| @@ -197,19 +198,6 @@ runner-dead-references: |
| # to pass for a runner host. |
| runner-host: runner-adapter-test runner-namespace-test |
| -# The static checks as CI runs them: the four shards of |
| -# .amadan/ci.d/10-lint@4, side by side. AMADAN_SHARD picks one. Each |
| -# stays a target of its own for a person to run. |
| -LINT_SHARD_0 := runner-dead-references build vet fmt-check budget migration-check |
| -LINT_SHARD_1 := staticcheck |
| -LINT_SHARD_2 := govulncheck |
| -LINT_SHARD_3 := gitleaks |
| -lint-shard: |
| - @test "$(AMADAN_SHARD_COUNT)" = 4 && test -n "$(LINT_SHARD_$(AMADAN_SHARD))" || \ |
| - { echo "lint-shard: shard $(AMADAN_SHARD) of $(AMADAN_SHARD_COUNT), but there are 4 lint shards; name the step 10-lint@4"; exit 1; } |
| - @echo "lint shard $(AMADAN_SHARD): $(LINT_SHARD_$(AMADAN_SHARD))" |
| - @$(MAKE) --no-print-directory $(LINT_SHARD_$(AMADAN_SHARD)) |
| - |
| # ci is the one gate: what a runner executes and what you run before |
| # pushing are the same definition. amadan's runner falls back to this |
| # target when .amadan/ci is absent; ci.d/ carries the same targets, |
diff --git a/internal/equipotest/foundation_test.go b/internal/equipotest/foundation_test.go| index 80f9afbd..de739fba 100644 |
| --- a/internal/equipotest/foundation_test.go |
| +++ b/internal/equipotest/foundation_test.go |
| @@ -184,29 +184,27 @@ func TestCIGateSteps(t *testing.T) { |
| t.Fatal(err) |
| } |
| var targets []string |
| - lint := map[string][]string{} |
| for _, line := range strings.Split(string(contents), "\n") { |
| if strings.HasPrefix(line, "ci:") { |
| targets = append(targets, strings.Fields(strings.TrimPrefix(line, "ci:"))...) |
| } |
| - if name, list, ok := strings.Cut(line, " := "); ok && strings.HasPrefix(name, "LINT_SHARD_") { |
| - lint[name] = strings.Fields(list) |
| - } |
| } |
| sort.Strings(targets) |
| if !reflect.DeepEqual(targets, want) { |
| t.Errorf("make ci targets = %v, want %v", targets, want) |
| } |
| - // The shards of the test step after the lanes, as ci-test.py lists them. |
| + // The shards after the lanes, as ci-test.py lists them: one line of |
| + // make targets each. |
| script, err := os.ReadFile(filepath.Join(root, "scripts", "ci-test.py")) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - extra := regexp.MustCompile(`(?m)^EXTRA_SHARDS = \[(.*)\]$`).FindSubmatch(script) |
| + extra := regexp.MustCompile(`(?s)\nEXTRA_SHARDS = \[\n(.*?)\n\]\n`).FindSubmatch(script) |
| if extra == nil { |
| t.Fatal("scripts/ci-test.py has no EXTRA_SHARDS list") |
| } |
| - extraShards := strings.Fields(strings.NewReplacer(`"`, "", ",", " ").Replace(string(extra[1]))) |
| + extraLines := strings.Split(string(extra[1]), "\n") |
| + extraTargets := strings.Fields(strings.NewReplacer(`"`, "", ",", " ", "[", "", "]", "").Replace(string(extra[1]))) |
| lanes := strings.Count(string(script), "\n (\"") |
| bin := t.TempDir() |
| if err := os.WriteFile(filepath.Join(bin, "make"), []byte("#!/bin/sh\nprintf '%s\\n' \"$@\"\n"), 0755); err != nil { |
| @@ -240,24 +238,16 @@ func TestCIGateSteps(t *testing.T) { |
| for _, path := range paths { |
| _, shards, _ := strings.Cut(filepath.Base(path), "@") |
| for _, target := range run(path) { |
| - switch target { |
| - case "test-shard": |
| - // CI runs make test as its lanes, then the extra shards. |
| - if want := strconv.Itoa(lanes + len(extraShards)); shards != want { |
| - t.Errorf("%s: %d lanes and %d extra shards need @%s", path, lanes, len(extraShards), want) |
| - } |
| - steps = append(steps, "test") |
| - steps = append(steps, extraShards...) |
| - case "lint-shard": |
| - if want := strconv.Itoa(len(lint)); shards != want { |
| - t.Errorf("%s: %d lint shards need @%s", path, len(lint), want) |
| - } |
| - for _, list := range lint { |
| - steps = append(steps, list...) |
| - } |
| - default: |
| + if target != "ci-shard" { |
| steps = append(steps, target) |
| + continue |
| + } |
| + // CI runs make test as its lanes, then the extra shards. |
| + if want := strconv.Itoa(lanes + len(extraLines)); shards != want { |
| + t.Errorf("%s: %d lanes and %d extra shards need @%s", path, lanes, len(extraLines), want) |
| } |
| + steps = append(steps, "test") |
| + steps = append(steps, extraTargets...) |
| } |
| } |
| sort.Strings(steps) |
diff --git a/scripts/ci-test.py b/scripts/ci-test.py| index 8242be13..aa609ea7 100755 |
| --- a/scripts/ci-test.py |
| +++ b/scripts/ci-test.py |
| @@ -3,16 +3,17 @@ |
| scripts/ci-test.py all every lane in one go test (make test) |
| scripts/ci-test.py lane NAME one lane (make test-lane LANE=NAME) |
| - scripts/ci-test.py shard the lane AMADAN_SHARD names (make test-shard) |
| + scripts/ci-test.py shard the shard AMADAN_SHARD names (make ci-shard) |
| scripts/ci-test.py quarantine the quarantined tests (make test-quarantine) |
| scripts/ci-test.py lanes print each lane and its packages |
| The slow packages each have a lane of their own and "rest" holds every |
| other package. CI runs the lanes side by side as the shards of one step, |
| -.amadan/ci.d/30-test@N: amadan runs separate steps one after another, and |
| +.amadan/ci.d/20-check@N: amadan runs separate steps one after another, and |
| a step's @N shards are how it runs work in parallel. A lane's packages |
| -pass or fail in that shard's own log. The quarantine and the runner host |
| -checks (make runner-host) are the last two shards of the same step. |
| +pass or fail in that shard's own log. The quarantine, the runner host |
| +checks (make runner-host) and the static checks are shards of the same |
| +step, after the lanes. |
| Results are cached: go test replays a pass for a package whose test |
| binary, declared files and environment are unchanged (internal/testci |
| @@ -37,21 +38,49 @@ TAGS = "testbuild" |
| TIMEOUT = "15m" |
| # Lane order is the shard index: shard 0 runs the first lane. After the |
| -# lanes come EXTRA_SHARDS. Keep the count in .amadan/ci.d/30-test@N equal |
| +# lanes come EXTRA_SHARDS. Keep the count in .amadan/ci.d/20-check@N equal |
| # to the number of lanes plus the extra shards. |
| +# |
| +# A lane is (name, packages, tests). With tests, the lane runs only those |
| +# of its one package: "TestX" is a test, "TestX/name" one of its subtests, |
| +# and anything starting with ^ is a regular expression over test names. |
| +# A lane of the same package without tests runs everything the others do |
| +# not name, so a new test always lands somewhere. Split a package when its |
| +# lane is the slowest shard, by the times its shard prints; the measured |
| +# seconds beside each lane are test time on a 32 CPU hosted machine. |
| +HEADLESS, RUNNER, DIRECTLIVE, THINTEST = "./internal/headless", "./internal/runner", "./internal/directlive", "./internal/thintest" |
| LANES = [ |
| - ("headless", ["./internal/headless"]), |
| - ("thintest", ["./internal/thintest"]), |
| - ("directlive", ["./internal/directlive"]), |
| - ("runner-thin", ["./internal/runner/thin"]), |
| - ("runner", ["./internal/runner"]), |
| - ("contracts", ["./internal/equipotest", "./internal/plan3test"]), |
| - ("rest", None), # every package no other lane names |
| + ("headless-work", [HEADLESS], ["TestHeadless/4c_rebase", "TestHeadless/4b_ask", "TestHeadless/4c_checks_card", "TestHeadless/4_step_crash"]), # 54 |
| + ("headless-review", [HEADLESS], ["TestHeadless/4_review", "TestHeadless/2b_access", "TestHeadless/runner_crash", "TestHeadless/2b_first_message", "TestHeadless/4_checks_honest", "TestHeadless/7_stream_resume", "TestHeadless/2b_notebook", "TestHeadless/2b_move_in"]), # 50 |
| + ("headless-connections", [HEADLESS], ["TestHeadlessConnections"]), # 52 without the quarantined |
| + ("headless-mac", [HEADLESS], ["TestMacWorker", "TestHeadlessAttachments", "TestHeadlessPrewarm"]), # 43 |
| + ("headless-rest", [HEADLESS], None), # 56 of TestHeadless and 40 of the others |
| + ("thintest-contracts", [THINTEST], ["^TestContract[A-M]"]), |
| + ("thintest-rest", [THINTEST], None), |
| + ("directlive-isolated", [DIRECTLIVE], ["TestCoordinatorFailureIsolatedFakeCLI"]), # 77 |
| + ("directlive-controls", [DIRECTLIVE], ["TestAutomaticControlsFakeCLI"]), # 64 |
| + ("directlive-rest", [DIRECTLIVE], None), # three of 40 side by side |
| + ("runner-thin", ["./internal/runner/thin"], None), # 53 |
| + ("runner-bug", [RUNNER], ["TestDirectBugWorkflow", "TestEnrolKeepsTheRole"]), # 59 |
| + ("runner-plans", [RUNNER], ["TestPlanWorkflowCandidateOrder", "TestPlanWorkflowFeature", "TestCoordinatorRecoveryCallRefusalKeepsServing", "TestCoordinatorRefusalMatrix"]), # 68, two side by side |
| + ("runner-rest", [RUNNER], None), # 55 |
| + ("equipotest", ["./internal/equipotest"], None), |
| + ("plan3test", ["./internal/plan3test"], None), # 88 |
| + ("rest", None, None), # every package no other lane names |
| ] |
| # Shards after the lanes: work that is not a lane of packages but runs |
| -# beside them, each a make target. |
| -EXTRA_SHARDS = ["test-quarantine", "runner-host"] |
| +# beside them, each a list of make targets run in order. The static |
| +# checks are here too: hosted CI runs steps one after another and only |
| +# shards side by side, so a lint step of its own would only add its time. |
| +EXTRA_SHARDS = [ |
| + ["test-quarantine"], |
| + ["runner-host"], |
| + ["runner-dead-references", "build", "vet", "fmt-check", "budget", "migration-check"], |
| + ["staticcheck"], |
| + ["govulncheck"], |
| + ["gitleaks"], |
| +] |
| # Packages whose results must never come from the cache, with the reason. |
| # They run with -count=1 inside their lane. |
| @@ -79,14 +108,42 @@ def all_packages(): |
| def lane_packages(name): |
| - for lane, packages in LANES: |
| + for lane, packages, _ in LANES: |
| if lane != name: |
| continue |
| if packages is not None: |
| return packages |
| - named = {p for _, ps in LANES if ps for p in ps} |
| + named = {p for _, ps, _ in LANES if ps for p in ps} |
| return [p for p in all_packages() if p not in named] |
| - sys.exit(f"ci-test: unknown lane {name!r}; lanes: {', '.join(l for l, _ in LANES)}") |
| + sys.exit(f"ci-test: unknown lane {name!r}; lanes: {', '.join(l for l, _, _ in LANES)}") |
| + |
| + |
| +def test_pattern(tests): |
| + """The go test -run or -skip pattern naming exactly tests.""" |
| + parts = [] |
| + for t in tests: |
| + if t.startswith("^"): |
| + parts.append(t) |
| + else: |
| + parts.append("/".join("^" + re.escape(level) + "$" for level in t.split("/"))) |
| + return "|".join(parts) |
| + |
| + |
| +def lane_flags(name): |
| + """-run for a lane that names tests; -skip, for a lane that does not, |
| + of every test the other lanes of its package name.""" |
| + for lane, packages, tests in LANES: |
| + if lane != name: |
| + continue |
| + if tests: |
| + if packages is None or len(packages) != 1: |
| + sys.exit(f"ci-test: lane {name} names tests, so it must name one package") |
| + return ["-run", test_pattern(tests)] |
| + if packages is None: |
| + return [] |
| + taken = [t for other, ps, ts in LANES if other != name and ts and ps[0] in packages for t in ts] |
| + return ["-skip", test_pattern(taken)] if taken else [] |
| + return [] |
| def fingerprint(): |
| @@ -146,7 +203,7 @@ def rastrillo(): |
| "RASTRILLO", "go run amadan.net/rastrillo/rastrillo/cmd/rastrillo")) |
| -def budget_test(packages, env): |
| +def budget_test(packages, env, flags=()): |
| """One rastrillo budget test over packages; returns its exit status.""" |
| status = 0 |
| cached = [p for p in packages if p not in UNCACHED] |
| @@ -156,8 +213,8 @@ def budget_test(packages, env): |
| continue |
| for p in group if extra else []: |
| print(f"uncached: {p}: {UNCACHED[p]}", flush=True) |
| - cmd = rastrillo() + ["budget", "test", "-tags", TAGS, "-timeout", TIMEOUT] + extra + group |
| - print("+ " + " ".join(cmd), flush=True) |
| + cmd = rastrillo() + ["budget", "test", "-tags", TAGS, "-timeout", TIMEOUT] + extra + list(flags) + group |
| + print("+ " + " ".join(shlex.quote(c) for c in cmd), flush=True) |
| status = run_reporting_misses(cmd, env) or status |
| return status |
| @@ -187,7 +244,7 @@ def run_reporting_misses(cmd, env): |
| def run_lane(name): |
| packages = lane_packages(name) |
| print(f"test lane {name}: {' '.join(packages)}", flush=True) |
| - return budget_test(packages, budget_env(environment(False))) |
| + return budget_test(packages, budget_env(environment(False)), lane_flags(name)) |
| def run_all(): |
| @@ -206,12 +263,15 @@ def run_shard(): |
| shards = len(LANES) + len(EXTRA_SHARDS) |
| if count != shards or not 0 <= index < count: |
| sys.exit(f"ci-test: shard {index} of {count}, but there are {len(LANES)} lanes and " |
| - f"{len(EXTRA_SHARDS)} extra shards; name the step 30-test@{shards}") |
| + f"{len(EXTRA_SHARDS)} extra shards; name the step 20-check@{shards}") |
| if index < len(LANES): |
| return run_lane(LANES[index][0]) |
| - target = EXTRA_SHARDS[index - len(LANES)] |
| - print(f"test shard {index}: make {target}", flush=True) |
| - return subprocess.call(["make", "--no-print-directory", target]) |
| + targets = EXTRA_SHARDS[index - len(LANES)] |
| + print(f"shard {index}: make {' '.join(targets)}", flush=True) |
| + # runner-host reruns tests the lanes ran; the quarantine shard beside |
| + # it is where a quarantined one of them runs, with its retry. |
| + env = dict(os.environ, EQUIPO_QUARANTINE="skip") if targets == ["runner-host"] else None |
| + return subprocess.call(["make", "--no-print-directory"] + targets, env=env) |
| # The quarantine. |
| @@ -324,8 +384,8 @@ def main(argv): |
| if argv == ["quarantine"]: |
| return run_quarantine() |
| if argv == ["lanes"]: |
| - for name, _ in LANES: |
| - print(name + ": " + " ".join(lane_packages(name))) |
| + for name, _, _ in LANES: |
| + print(name + ": " + " ".join(lane_packages(name) + lane_flags(name))) |
| return 0 |
| print(__doc__, file=sys.stderr) |
| return 2 |