Skip to content

Commit 8bb592c

Browse files
insipxclaude
andcommitted
fix(node-sdk): deflake should stream preferences test
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 #3831 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 701cc12 commit 8bb592c

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

sdks/js/node-sdk/test/Preferences.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,25 @@ describe("Preferences", () => {
205205
await client2.conversations.syncAll();
206206
await sleep(1000);
207207

208-
setTimeout(() => {
208+
const preferences: UserPreferenceUpdate[] = [];
209+
210+
// Safety net: end the stream if the expected updates never arrive, so the
211+
// assertion below fails clearly instead of the test hanging until timeout.
212+
// The HmacKeyUpdate events depend on network propagation, so we collect
213+
// until we have all 4 expected updates rather than ending on a fixed timer.
214+
const endTimeout = setTimeout(() => {
209215
void stream.end();
210-
}, 100);
216+
}, 10000);
211217

212-
const preferences: UserPreferenceUpdate[] = [];
213218
for await (const update of stream) {
214219
preferences.push(...update);
220+
if (preferences.length >= 4) {
221+
break;
222+
}
215223
}
224+
clearTimeout(endTimeout);
225+
await stream.end();
226+
216227
expect(preferences.length).toBe(4);
217228
const consentUpdate1 = preferences[0] as Extract<
218229
UserPreferenceUpdate,

0 commit comments

Comments
 (0)