From 4e4fce7e89542978d09fd98971603079d9085956 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 31 Dec 2024 08:51:38 +0000 Subject: [PATCH] Add test --- .../WebSocketStateMachineTests.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Tests/WebSocketTests/WebSocketStateMachineTests.swift b/Tests/WebSocketTests/WebSocketStateMachineTests.swift index a85d5c8..3328d98 100644 --- a/Tests/WebSocketTests/WebSocketStateMachineTests.swift +++ b/Tests/WebSocketTests/WebSocketStateMachineTests.swift @@ -96,4 +96,34 @@ final class WebSocketStateMachineTests: XCTestCase { return } } + + // Verify ping buffer size doesnt grow + func testPingBufferSize() async throws { + var stateMachine = WebSocketStateMachine(autoPingSetup: .enabled(timePeriod: .milliseconds(1))) + var currentBuffer = ByteBuffer() + var count = 0 + while true { + switch stateMachine.sendPing() { + case .sendPing(let buffer): + XCTAssertEqual(buffer.readableBytes, 16) + currentBuffer = buffer + count += 1 + if count > 4 { + return + } + + case .wait(let time): + try await Task.sleep(for: time) + stateMachine.receivedPong(frameData: currentBuffer) + + case .closeConnection: + XCTFail("Should not timeout") + return + + case .stop: + XCTFail("Should not stop") + return + } + } + } }