Skip to content

Commit

Permalink
Fix tests for large WebSocket sends
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CendioOssman committed Aug 29, 2024
1 parent ffb4c0b commit 50e4685
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions tests/test.websock.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,15 @@ describe('Websock', function () {
});
it('should implicitly split a large buffer', function () {
let str = '';
for (let i = 0;i <= bufferSize/5;i++) {
str += '\x12\x34\x56\x78\x90';
let expected = [];
for (let i = 0;i < bufferSize * 3;i++) {
let byte = Math.random() * 0xff;
str += String.fromCharCode(byte);
expected.push(byte);
}

sock.sQpushString(str);

let expected = [];
for (let i = 0;i < bufferSize/5;i++) {
expected.push(0x12);
expected.push(0x34);
expected.push(0x56);
expected.push(0x78);
expected.push(0x90);
}
sock.flush();

expect(sock).to.have.sent(new Uint8Array(expected));
});
Expand Down Expand Up @@ -308,24 +303,15 @@ describe('Websock', function () {
});
it('should implicitly split a large buffer', function () {
let buffer = [];
for (let i = 0;i <= bufferSize/5;i++) {
buffer.push(0x12);
buffer.push(0x34);
buffer.push(0x56);
buffer.push(0x78);
buffer.push(0x90);
let expected = [];
for (let i = 0;i < bufferSize * 3;i++) {
let byte = Math.random() * 0xff;
buffer.push(byte);
expected.push(byte);
}

sock.sQpushBytes(new Uint8Array(buffer));

let expected = [];
for (let i = 0;i < bufferSize/5;i++) {
expected.push(0x12);
expected.push(0x34);
expected.push(0x56);
expected.push(0x78);
expected.push(0x90);
}
sock.flush();

expect(sock).to.have.sent(new Uint8Array(expected));
});
Expand Down

0 comments on commit 50e4685

Please sign in to comment.