Skip to content

Commit dd2fa26

Browse files
author
weiesky.wangc
committed
fix(test): deterministic brotli decode in sse-compression broadcast test
Replace async polling decodeBr() with encoder.end() + brotliDecompressSync. The async approach is fragile under CI CPU constraints (Node 24 zlib timing differs from local), causing the broadcast frame to never appear in decoded output within the 500-tick polling window.
1 parent 1454d6f commit dd2fa26

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

test/sse-compression.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,21 @@ describe('GET /events wire compression', () => {
165165
const expected = `data: ${JSON.stringify(entry)}\n\n`;
166166
const plainTail = Buffer.concat(plainRes.chunks.slice(plainMark)).toString();
167167
assert.equal(plainTail, expected);
168-
const decoded = await decodeBr(brRes, (t) => t.includes(expected));
169-
assert.ok(decoded.includes(expected), 'compressed client received the broadcast frame');
168+
169+
// Deterministic decode: end the encoder to finalize the compressed stream,
170+
// then decompress synchronously. The polling-based decodeBr() is fragile
171+
// under CI CPU constraints (Node 24 zlib timing differs from local).
172+
const enc = brRes._wireEnc;
173+
assert.ok(enc, 'br encoder exists');
174+
// Wait for the scheduled flush to push the broadcast frame into the encoder's
175+
// internal pipeline (setImmediate in scheduleFlush). Without this, end() can
176+
// drain a still-empty encoder buffer and the broadcast frame never appears.
177+
await until(() => brRes.chunks.length > 0);
178+
enc.end();
179+
// Wait for the pipe to drain: end() sends FINISH through encoder -> pipe -> res.
180+
await until(() => brRes.ended);
181+
const decompressed = zlib.brotliDecompressSync(Buffer.concat(brRes.chunks)).toString();
182+
assert.ok(decompressed.includes(expected), 'compressed client received the broadcast frame');
170183
plainRes.emit('close');
171184
brRes.emit('close');
172185
});

0 commit comments

Comments
 (0)