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

View File

@@ -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));
});
@@ -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));
});