Files
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

61 lines
2.6 KiB
Swift

import XCTest
@testable import WebProxyTransport
final class WebProxySendBatcherTests: XCTestCase {
private func frames(_ sizes: [Int]) -> [Data] {
return sizes.map { Data(count: $0) }
}
func testEmptyQueueBatchesNothing() {
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: [], isFirstMessage: false, maximumFrames: 4096, maximumBytes: 2048), 0)
}
/// The relay's session-create body must be the lone HELLO frame; it caps that
/// request at 64 bytes, so the first message can never carry a batch.
func testFirstMessageIsAlwaysAlone() {
let pending = self.frames([16, 16, 16])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: true, maximumFrames: 4096, maximumBytes: 2048), 1)
}
func testSubsequentMessagesCoalesce() {
let pending = self.frames([16, 16, 16])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: false, maximumFrames: 4096, maximumBytes: 2048), 3)
}
func testStopsAtTheByteBudget() {
let pending = self.frames([600, 600, 600, 600])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: false, maximumFrames: 4096, maximumBytes: 2048), 3)
}
func testStopsAtTheFrameBudget() {
let pending = self.frames([1, 1, 1, 1, 1])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: false, maximumFrames: 2, maximumBytes: 2048), 2)
}
/// A single frame larger than the batch budget still has to go, or the queue wedges.
func testAnOversizedLeadingFrameIsSentAlone() {
let pending = self.frames([5000, 8])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: false, maximumFrames: 4096, maximumBytes: 2048), 1)
}
func testNeverExceedsTheQueue() {
let pending = self.frames([8, 8])
XCTAssertEqual(WebProxySendBatcher.batchCount(pending: pending, isFirstMessage: false, maximumFrames: 4096, maximumBytes: 1 << 20), 2)
}
func testDefaultsMatchTheProtocolLimits() {
// 4096 frames is the bridge's hard cap: splitFrames throws past it.
XCTAssertEqual(WebProxyProtocol.maximumBatchFrames, 4096)
let pending = self.frames(Array(repeating: 8, count: 5000))
XCTAssertEqual(
WebProxySendBatcher.batchCount(
pending: pending,
isFirstMessage: false,
maximumFrames: WebProxyProtocol.maximumBatchFrames,
maximumBytes: WebProxyProtocol.defaultBatchSize
),
4096
)
}
}