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.
This commit is contained in:
Pierre Ossman 2024-08-29 16:51:51 +02:00
parent ffb4c0bf56
commit 50e4685bff
1 changed files with 12 additions and 26 deletions

View File

@ -261,20 +261,15 @@ describe('Websock', function () {
}); });
it('should implicitly split a large buffer', function () { it('should implicitly split a large buffer', function () {
let str = ''; let str = '';
for (let i = 0;i <= bufferSize/5;i++) { let expected = [];
str += '\x12\x34\x56\x78\x90'; for (let i = 0;i < bufferSize * 3;i++) {
let byte = Math.random() * 0xff;
str += String.fromCharCode(byte);
expected.push(byte);
} }
sock.sQpushString(str); sock.sQpushString(str);
sock.flush();
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);
}
expect(sock).to.have.sent(new Uint8Array(expected)); expect(sock).to.have.sent(new Uint8Array(expected));
}); });
@ -308,24 +303,15 @@ describe('Websock', function () {
}); });
it('should implicitly split a large buffer', function () { it('should implicitly split a large buffer', function () {
let buffer = []; let buffer = [];
for (let i = 0;i <= bufferSize/5;i++) { let expected = [];
buffer.push(0x12); for (let i = 0;i < bufferSize * 3;i++) {
buffer.push(0x34); let byte = Math.random() * 0xff;
buffer.push(0x56); buffer.push(byte);
buffer.push(0x78); expected.push(byte);
buffer.push(0x90);
} }
sock.sQpushBytes(new Uint8Array(buffer)); sock.sQpushBytes(new Uint8Array(buffer));
sock.flush();
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);
}
expect(sock).to.have.sent(new Uint8Array(expected)); expect(sock).to.have.sent(new Uint8Array(expected));
}); });