From 170d315f4e424787ecfb8dd1bf23c73caafd0e51 Mon Sep 17 00:00:00 2001 From: Gus Narea Date: Fri, 25 Jun 2021 18:48:21 +0100 Subject: [PATCH] fix: Use FIFO queue when buffering peer messages BREAKING CHANGE: We were using an inconsistent FIFO/LIFO approach by mistake. --- src/lib/MockPeer.ts | 10 +++++----- src/lib/MockWebSocket.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/MockPeer.ts b/src/lib/MockPeer.ts index bc15e89..881d01c 100644 --- a/src/lib/MockPeer.ts +++ b/src/lib/MockPeer.ts @@ -32,16 +32,16 @@ export abstract class MockPeer { public async receive(): Promise { 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 { diff --git a/src/lib/MockWebSocket.ts b/src/lib/MockWebSocket.ts index be94371..c70f7fc 100644 --- a/src/lib/MockWebSocket.ts +++ b/src/lib/MockWebSocket.ts @@ -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 {