Skip to content

Commit 50e4685

Browse files
committed
Fix tests for large WebSocket sends
These failed to test that the data was correctly split as they only checked the first chunk transmitted. Use random values to avoid the risk of aligning our test data with the split boundaries and hence allowing false positives.
1 parent ffb4c0b commit 50e4685

1 file changed

Lines changed: 12 additions & 26 deletions

File tree

tests/test.websock.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,15 @@ describe('Websock', function () {
261261
});
262262
it('should implicitly split a large buffer', function () {
263263
let str = '';
264-
for (let i = 0;i <= bufferSize/5;i++) {
265-
str += '\x12\x34\x56\x78\x90';
264+
let expected = [];
265+
for (let i = 0;i < bufferSize * 3;i++) {
266+
let byte = Math.random() * 0xff;
267+
str += String.fromCharCode(byte);
268+
expected.push(byte);
266269
}
267270

268271
sock.sQpushString(str);
269-
270-
let expected = [];
271-
for (let i = 0;i < bufferSize/5;i++) {
272-
expected.push(0x12);
273-
expected.push(0x34);
274-
expected.push(0x56);
275-
expected.push(0x78);
276-
expected.push(0x90);
277-
}
272+
sock.flush();
278273

279274
expect(sock).to.have.sent(new Uint8Array(expected));
280275
});
@@ -308,24 +303,15 @@ describe('Websock', function () {
308303
});
309304
it('should implicitly split a large buffer', function () {
310305
let buffer = [];
311-
for (let i = 0;i <= bufferSize/5;i++) {
312-
buffer.push(0x12);
313-
buffer.push(0x34);
314-
buffer.push(0x56);
315-
buffer.push(0x78);
316-
buffer.push(0x90);
306+
let expected = [];
307+
for (let i = 0;i < bufferSize * 3;i++) {
308+
let byte = Math.random() * 0xff;
309+
buffer.push(byte);
310+
expected.push(byte);
317311
}
318312

319313
sock.sQpushBytes(new Uint8Array(buffer));
320-
321-
let expected = [];
322-
for (let i = 0;i < bufferSize/5;i++) {
323-
expected.push(0x12);
324-
expected.push(0x34);
325-
expected.push(0x56);
326-
expected.push(0x78);
327-
expected.push(0x90);
328-
}
314+
sock.flush();
329315

330316
expect(sock).to.have.sent(new Uint8Array(expected));
331317
});

0 commit comments

Comments
 (0)