Files
Michael Suchacz dd0346c8a6 test(enterprise): avoid fixture and provisioning timer waits (#29527)
Two prebuild tests constructed a `StoreReconciler` without starting its
job-notification worker. `TestWorkspaceProvisionerdServerMetrics` waited
for the acquirer's 30s backup poll; `TestClaimPrebuild` advanced a mock
backup ticker by hand. Two prebuild tables also paid for an
unnecessarily expensive fixture per leaf.

The two provisioning tests now start the reconciler and stop it in
cleanup; their unadvanced mock clocks prevent periodic reconciliation
from interfering with explicit reconciliation calls. Polling moves to
`IntervalFast`, with the existing timeouts unchanged.
`TestClaimPrebuild` removes its hand-rolled acquirer and checks freshly
fetched rows when waiting for a replacement prebuild.
`TestMetricsCollector` shares one database with a rolled-back
transaction per leaf, and `TestReconcileAll` uses `dbtestutil.NewDB`
plus `dbgen.User` instead of a full coderd.

`TestEnterpriseCreateWithPreset` had the same 30s wait. #29458 fixed it
on main by posting the pending jobs itself, so after the rebase onto
main this PR only moves that test's polling to `IntervalFast`. Its table
row and the full `enterprise/cli` package medians below were measured
before #29458 landed.

| Test | Before | After |
|---|---|---|
| `enterprise/cli/TestEnterpriseCreateWithPreset` (2 leaves) | 64.56s |
1.35s |
| `enterprise/coderd/TestWorkspaceProvisionerdServerMetrics` | 30.94s |
0.69s |
| `prebuilds/TestMetricsCollector` (80 leaves) | 17.56s | 7.09s |
| `prebuilds/TestClaimPrebuild` (10 leaves) | 24.05s | 18.46s |
| `prebuilds/TestReconcileAll` (16 leaves) | 8.17s | 6.22s |

Independent review measurements: median summed leaf time from two
targeted runs per side in A-B-B-A order, against merge base
`0ea777a341`, using `go test -json -tags=testsmallbatch -count=1 -v -p 1
-parallel 8`. The CLI and coderd tests were selected individually; the
three prebuild tests ran together. Other agents shared the machine, so
fixture timings were noisy. The provisioning speedups hold; the measured
prebuild fixture ratios are smaller than the original estimates.

Selected-prebuild-test package elapsed was 5.50s/7.61s before and
2.36s/6.29s after, with medians of 6.56s and 4.33s. These are not
full-package timings. Separate full-package A-B-B-A runs measured
`enterprise/coderd/prebuilds` at 31.62s/18.63s before and 20.78s/21.63s
after, with medians of 25.12s and 21.20s. Full `enterprise/cli` package
medians were 54.09s before and 26.21s after. The full
`enterprise/coderd` package was not run locally.

<details>
<summary>Investigation notes</summary>

- The reconciler publishes queued provisioner jobs from a worker started
by `Run` (`reconcile.go:220-241`). Reconciliation itself only runs after
a mock-clock tick; none of these tests advances that clock. `Stop` uses
a fresh `WaitShort` context and is registered after database/pubsub
cleanup, so it executes first.
- `coderdenttest.GetRunningPrebuilds` has one caller, the
workspace-metrics test. Its polling interval changes, not its context
deadline.
- Both the metrics collector and its reconciler receive each leaf's
transaction store (`metricscollector_test.go:207-221`). `UpdateState`
passes that same store to `SnapshotState`, whose nested transaction
reuses the existing transaction. Assertions require two templates and
non-nil metric series with exact values.
- The post-claim check now waits for the fetched prebuild count to
return from one to two (`claim_test.go:324-360`), rather than checking
the unchanged pre-claim map.
- The original 6.8s/7.4s to 4.5s/4.6s prebuild measurements selected
only the three changed tests. The measurements above distinguish that
selection from the full package.

Not changed, with reasons: `TestWorkspaceTagsTerraform` and
`TestWorkspaceTemplateParamsChange` run real Terraform, which is the
coverage; `TestPrebuildReconciliation` cannot use rolled-back
transactions without collapsing its separate advisory-lock and write
transactions; `TestReplicas` and `TestConn_CoordinatorRollingRestart`
are bounded by tailnet handshake retry timing, and an earlier
shared-pubsub prototype did not help.

Validation: all five changed tests pass with `-count=5` and `-race
-count=2`; both full-package comparisons pass on both sides; `gofmt -l`,
`git diff --check`, and scoped `golangci-lint` are clean. No source
fixes were needed during independent review. Codex completed review of
`7b81822414` with no findings. Relevant Go and lint CI jobs passed. No
production code changes.

</details>

_Investigated, implemented, and validated by Coder Agents on behalf of
@ibetitsmike._

Rebased onto `9cfe27063df`. `go build` and `go vet` of the four touched
packages, scoped `golangci-lint` and `paralleltestctx`, and the five
changed tests (`-count=1`, then `-race -count=2`) pass.

> Xum (an AI agent) rebased this PR onto main on behalf of @ibetitsmike.
2026-10-07 14:24:58 +02:00
..