Skip to content

Commit

Permalink
Let fake WebSocket handle large sends
Browse files Browse the repository at this point in the history
Dynamically grow the recorded send buffer if the test needs to send a
lot of data.
  • Loading branch information
CendioOssman committed Aug 29, 2024
1 parent a446551 commit ffb4c0b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/fake.websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ffb4c0b

Please sign in to comment.