Skip to content

Commit

Permalink
fix: Use FIFO queue when buffering peer messages
Browse files Browse the repository at this point in the history
BREAKING CHANGE: We were using an inconsistent FIFO/LIFO approach by mistake.
  • Loading branch information
gnarea committed Jun 25, 2021
1 parent c56e17e commit 170d315
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/lib/MockPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export abstract class MockPeer {
public async receive(): Promise<WSData> {
this.requireConnectionStillOpen();

const lastMessage = this.popLastPeerMessage();
if (lastMessage) {
return lastMessage;
const oldestMessage = this.popOldestPeerMessage();
if (oldestMessage) {
return oldestMessage;
}

return this.peerWebSocket.getLastMessageSent();
}

public popLastPeerMessage(): WSData | undefined {
return this.peerWebSocket.popLastMessage();
public popOldestPeerMessage(): WSData | undefined {
return this.peerWebSocket.popOldestMessage();
}

public async waitForPeerClosure(): Promise<CloseFrame> {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/MockWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class MockWebSocket extends EventEmitter {
/**
* @internal
*/
public popLastMessage(): WSData | undefined {
return this.messagesSent.pop();
public popOldestMessage(): WSData | undefined {
return this.messagesSent.shift();
}

public close(code?: number, reason?: string): void {
Expand Down

0 comments on commit 170d315

Please sign in to comment.