fluentcart-mcp: stop the cancellation test racing the clock - #126
Merged
Conversation
'removes active listeners on timeout and service shutdown' slept a real 20ms against a 10ms timeout and then asserted the entry had expired. True on an idle machine; false whenever a loaded runner stretched the gap. It failed the Node 26 lane and passed the Node 24 lane in the same CI run, which is as clear a statement of wall-clock dependence as a test can make. Now on fake timers, matching the tombstone test directly above it, with the clock advanced by exactly the timeout. Expiry becomes a fact rather than a margin. Mutation-checked, because a fake-timer test is an easy way to write one that passes regardless: advancing 0 instead of 10 reproduces the original failure exactly — expected true to be false — so the assertion still tests expiry. Restored, then run five times: 19/19 each time. The close() in the new finally block is a no-op, since close() returns early on this.closed and the test closes mid-body on purpose. The three remaining real-timer sleeps in the suite are a different shape: they sit inside a loader or handler to simulate latency, so a slower runner lengthens the simulated work rather than invalidating an assertion. Left alone.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
removes active listeners on timeout and service shutdownslept a real 20ms against a 10ms timeout, then asserted the entry had expired. True on an idle machine; false whenever a loaded runner stretched the gap.It failed the Node 26 lane and passed the Node 24 lane in the same CI run on #125 — about as clear a statement of wall-clock dependence as a test can make — then passed clean on re-run.
The fix
Fake timers, matching the tombstone test directly above it in the same file, with the clock advanced by exactly the timeout. Expiry becomes a fact rather than a margin.
Mutation-checked, because this is an easy thing to get wrong
A fake-timer test is a convenient way to write one that passes regardless of behaviour. Advancing
0instead of10reproduces the original failure exactly —expected true to be false— so the assertion still tests expiry rather than the timer call. Restored, then run five times: 19/19 every time.The
close()in the newfinallyis a deliberate no-op:close()returns early onthis.closed, and the test closes mid-body on purpose to exercise shutdown.The other real-timer sleeps stay
Three remain in the suite — two in
commerce/cache.test.ts, one incode-mode/sandbox.test.ts. They are a different shape: the sleep sits inside a loader or handler to simulate latency, so a slower runner lengthens the simulated work rather than invalidating the assertion. Coalescing still coalesces; a slow read is still slow. Only the cancellation test raced a deadline.2823 unit tests, lint across 310 files, tests typecheck — all clean.