Skip to content

test: replace real-clock waits with mock clocks - #29458

Draft
ibetitsmike wants to merge 1 commit into
mainfrom
mike/test-mock-clocks
Draft

ibetitsmike wants to merge 1 commit into
mainfrom
mike/test-mock-clocks

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Several tests waited on real wall-clock time. The httpapi heartbeat tests slept 3 x HeartbeatInterval (45s of slot time, 15s of package wall), TestEnterpriseCreateWithPreset waited ~31s per subtest for provisionerd's 30s backup poll (tests that call StoreReconciler.ReconcilePreset directly never publish the job-posted pubsub notification, because only Run drains that channel), and a handful of tests used time.Sleep.

This change drives the heartbeat tickers with a quartz mock clock (adding ServerSentEventSenderWithClock so the SSE sender's ticker is injectable; production callers are unchanged), posts the pending provisioner jobs on the reconciler's behalf in the preset test, and replaces the remaining sleeps with channel barriers or deterministic waits. TestConn_BlockEndpoints keeps its 10s wait: it is a negative check with no hook inside magicsock to know when disco has settled.

Before / After

Local, go test -count=1 -tags=testsmallbatch -parallel=8:

Test / package Before After
httpapi heartbeat subtests (x2) 15.0s each 0.00s
ok coderd/httpapi 15.1s 5.0s
TestEnterpriseCreateWithPreset subtests (x2) 30.9s each 1.05s
ok enterprise/cli 36.8s 21.1s
TestWorkspaceActivityBump/Dial, /NotExceedMaxDeadline 4.1s / 3.9s 0.9s / 0.9s
TestConnectAll_LateServerReaped 2.0s 0.5s
Test_ConcurrentExecutionStrategy, Test_ParallelExecutionStrategy 1.0s / 2.0s 0.00s
ok scaletest/harness 3.6s 0.6s

The remaining ~5s in coderd/httpapi is the coder/websocket close-handshake timeout against the raw net.Pipe mock client in two unrelated subtests; left for a follow-up with a real websocket client fixture.

Validation

  • Targeted go test -count=1 -tags=testsmallbatch -parallel=8 on coderd/httpapi, enterprise/cli, coderd (TestWorkspaceActivityBump), coderd/x/chatd/mcpclient, scaletest/harness, tailnet: pass.
  • -race -count=2 -shuffle=on on every converted test: pass. Repeated runs (-count=5 activity bump and mcpclient, -count=3 preset test): pass.
  • golangci-lint run on all touched packages with a fresh cache: 0 issues.

Part of the test-suite speedup series (see #29457 for the package-ordering PR); independent of the other PRs.

Remote validation

Remote run on a dogfood workspace (separate compute), chat https://dogfood.cdr.dev/agents/5bbe73d0-866a-4841-9cc3-c5e5b4d97e44, tested head cc572708ed0 against base 9d973372774 on the same machine: coderd/httpapi 15.06s to 5.09s; TestEnterpriseCreateWithPreset subtests 31.7s to 1.06s each; TestWorkspaceActivityBump 4.00s to 0.95s; mcpclient 2.05s to 1.06s; scaletest/harness 3.54s to 0.56s. -race -count=3 -shuffle=on on all five packages: pass, no race reports. Endorsed verdict: PASS. Reviewer note from the run: this PR adds a small production seam (ServerSentEventSenderWithClock, 23 lines in coderd/httpapi/httpapi.go).

Xum (an AI agent) authored this PR on behalf of @ibetitsmike.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant