Let fake WebSocket handle large sends

Dynamically grow the recorded send buffer if the test needs to send a
lot of data.
This commit is contained in:
Pierre Ossman 2024-08-29 16:51:16 +02:00
parent a4465516df
commit ffb4c0bf56

View File

@ -37,6 +37,15 @@ export default class FakeWebSocket {
} else {
data = new Uint8Array(data);
}
if (this.bufferedAmount + data.length > this._sendQueue.length) {
let newlen = this._sendQueue.length;
while (this.bufferedAmount + data.length > newlen) {
newlen *= 2;
}
let newbuf = new Uint8Array(newlen);
newbuf.set(this._sendQueue);
this._sendQueue = newbuf;
}
this._sendQueue.set(data, this.bufferedAmount);
this.bufferedAmount += data.length;
}