fix(node-sdk): deflake should stream preferences test - #3833
Open
insipx wants to merge 2 commits into
Open
Conversation
The `Preferences > should stream preferences` test ended its stream on a fixed 100ms timer, far shorter than the 2000ms used by every other streaming test. The two HmacKeyUpdate events depend on network propagation of newly-registered installations, so the 4th update frequently arrived after the 100ms window, ending the stream early and failing with `expected 3 to be 4`. Collect updates until all 4 expected preferences arrive, then end the stream, with a generous 10s safety-net timeout so a genuine regression fails with the same clear assertion instead of hanging. Resolves xmtp#3831 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Resolves #3831
Problem
The Node SDK integration test
Preferences > should stream preferencesis flaky (CI failure:expected 3 to be 4). It ends its preference stream on a fixed 100 ms timer — far shorter than the 2000 ms every other streaming test in this SDK uses:The test expects 4 updates: 2
ConsentUpdate+ 2HmacKeyUpdate. The twoHmacKeyUpdateevents come from registering new installations and depend on network propagation, so the 4th event frequently arrives after the 100 ms window.stream.end()then flushes the iterator early and the loop exits with only 3 updates collected.Fix
Collect updates until all 4 expected preferences have arrived, then end the stream, rather than ending on an arbitrary fixed timer. A generous 10 s safety-net timeout (well under vitest's 120 s
testTimeout) still ends the stream if fewer than 4 updates ever arrive, so a genuine regression fails with the same clearexpected N to be 4assertion instead of hanging.Scope
Test-only change. No production/library code touched. All existing assertions on update ordering, types, and payloads are unchanged.
Verification
eslintpasses on the modified file.typecheckerrors in this environment stem from the unbuilt@xmtp/node-bindingsnative crate (they affect every test file equally) and are unrelated to this change.🤖 Generated with Claude Code
Note
Fix flaky
should stream preferencestest by awaiting 4 updates instead of a fixed timeoutReplaces the fixed 100ms
setTimeoutthat terminated the preferences stream with a collection loop that exits once 4 updates are received. A 10s safety-net timeout ends the stream if updates never arrive, and is cleared after the loop exits. The stream is explicitly ended with an awaitedstream.end()call.Macroscope summarized 79c4197.