Repository navigation
chat-ui: drive timer-backstop hooks with an injected clock (CL-7488) - #678
Merged
Merged
Conversation
useTurnActivity's and useStreamingReply's backstop tests drove real setTimeout via sleep(), racing CI's sharded, CPU-contended test runs against their 20-60ms windows. Rework the harnesses in both suites to advance a synchronous fake clock instead.
useStreamingReply and useTurnActivity now take an optional Clock (now/ setTimeout/clearTimeout), defaulting to the real one, instead of calling Date.now()/setTimeout directly. This is what lets their tests advance a fake clock synchronously rather than racing real timers.
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.
Summary
packages/chat-ui/test/use-turn-activity.test.tsxanduse-streaming-reply.test.tsxdrove their backstop-timer assertions with realsetTimeout/sleep against 20-60ms windows. Since CL-7484 madebun run testrun packages concurrently (and CI shards them), those tests intermittently lost the race under CPU contention onbuild-test-shard (3).useTurnActivityanduseStreamingReplynow take an optionalClock(now/setTimeout/clearTimeout— see newpackages/chat-ui/src/clock.ts), defaulting to the real one (REAL_CLOCK), instead of callingDate.now()/setTimeoutdirectly.createFakeClock()test helper (packages/chat-ui/test/fake-clock.ts) instead of sleeping on the real clock —advance(ms)fires due timers immediately, so a 30ms/60ms backstop test takes ~0ms of wall time and can never race a contended CPU.Ran the whole
packages/chat-uisuite once and with--rerun-each 5: 4630/4630 pass, 0 fail (composer.test.tsxincluded — it did not fail locally, so nothing there needed touching).Resolves CL-7488
Test plan
bunx tsc --noEmit -p packages/chat-uibun test packages/chat-ui/test/use-turn-activity.test.tsx packages/chat-ui/test/use-streaming-reply.test.tsx --rerun-each 20— 540/540 passbun test packages/chat-ui— 926/926 passbun test packages/chat-ui --rerun-each 5— 4630/4630 pass