test: replace real-clock waits with mock clocks - #29458
Draft
ibetitsmike wants to merge 1 commit into
Draft
ibetitsmike wants to merge 1 commit into
ibetitsmike wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several tests waited on real wall-clock time. The httpapi heartbeat tests slept 3 x
HeartbeatInterval(45s of slot time, 15s of package wall),TestEnterpriseCreateWithPresetwaited ~31s per subtest for provisionerd's 30s backup poll (tests that callStoreReconciler.ReconcilePresetdirectly never publish the job-posted pubsub notification, because onlyRundrains that channel), and a handful of tests usedtime.Sleep.This change drives the heartbeat tickers with a quartz mock clock (adding
ServerSentEventSenderWithClockso 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_BlockEndpointskeeps 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:ok coderd/httpapiTestEnterpriseCreateWithPresetsubtests (x2)ok enterprise/cliTestWorkspaceActivityBump/Dial,/NotExceedMaxDeadlineTestConnectAll_LateServerReapedTest_ConcurrentExecutionStrategy,Test_ParallelExecutionStrategyok scaletest/harnessThe remaining ~5s in
coderd/httpapiis the coder/websocket close-handshake timeout against the rawnet.Pipemock client in two unrelated subtests; left for a follow-up with a real websocket client fixture.Validation
go test -count=1 -tags=testsmallbatch -parallel=8oncoderd/httpapi,enterprise/cli,coderd(TestWorkspaceActivityBump),coderd/x/chatd/mcpclient,scaletest/harness,tailnet: pass.-race -count=2 -shuffle=onon every converted test: pass. Repeated runs (-count=5activity bump and mcpclient,-count=3preset test): pass.golangci-lint runon 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
cc572708ed0against base9d973372774on the same machine:coderd/httpapi15.06s to 5.09s;TestEnterpriseCreateWithPresetsubtests 31.7s to 1.06s each;TestWorkspaceActivityBump4.00s to 0.95s;mcpclient2.05s to 1.06s;scaletest/harness3.54s to 0.56s.-race -count=3 -shuffle=onon 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 incoderd/httpapi/httpapi.go).