Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Dec 31, 2024
1 parent beeea9e commit 4e4fce7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Tests/WebSocketTests/WebSocketStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit 4e4fce7

Please sign in to comment.