Skip to content

Commit 4f55e6f

Browse files
committed
Counter-test for missing packets
1 parent 7feff02 commit 4f55e6f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Sources/LiveKit/Core/DataChannelPair.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class DataChannelPair: NSObject, @unchecked Sendable, Loggable {
231231
from lastSeq: UInt32
232232
) {
233233
if let first = buffer.peek(), first.sequence > lastSeq + 1 {
234-
log("Missing packets while retrying", .warning)
234+
log("Missing packet sequence while retrying: \(first.sequence) > \(lastSeq + 1)", .warning)
235235
}
236236
while let request = buffer.dequeue() {
237237
if request.sequence > lastSeq {

Tests/LiveKitTests/DataStream/DataChannelTests.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class DataChannelTests: LKTestCase, @unchecked Sendable {
2828
}
2929

3030
func testReliableRetry() async throws {
31-
let testData = ["abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", "🔥"].map { $0.data(using: .utf8)! }
31+
let testString = "abcdefghijklmnopqrstuvwxyz🔥"
32+
let testData = Array(repeating: String(repeating: testString, count: 128).data(using: .utf8)!, count: 128)
3233

3334
receivedExpectation.expectedFulfillmentCount = testData.count
3435
receivedExpectation.assertForOverFulfill = false
@@ -41,8 +42,14 @@ class DataChannelTests: LKTestCase, @unchecked Sendable {
4142
let receiving = rooms[1]
4243
let remoteIdentity = try XCTUnwrap(sending.remoteParticipants.keys.first)
4344

44-
Task { try await sending.startReconnect(reason: .debug) }
45-
Task { try await receiving.startReconnect(reason: .debug) }
45+
Task {
46+
try await Task.sleep(nanoseconds: 200_000_000) // 200 ms
47+
try await sending.startReconnect(reason: .debug)
48+
}
49+
Task {
50+
try await Task.sleep(nanoseconds: 400_000_000) // 400 ms
51+
try await receiving.startReconnect(reason: .debug)
52+
}
4653

4754
for data in testData {
4855
let userPacket = Livekit_UserPacket.with {
@@ -51,14 +58,14 @@ class DataChannelTests: LKTestCase, @unchecked Sendable {
5158
}
5259

5360
try await sending.send(userPacket: userPacket, kind: .reliable)
54-
try await Task.sleep(nanoseconds: 100_000_000) // 100 ms
61+
try await Task.sleep(nanoseconds: 10_000_000) // 10 ms
5562
}
5663
}
5764

58-
await fulfillment(of: [receivedExpectation], timeout: 5)
65+
await fulfillment(of: [receivedExpectation], timeout: 10)
5966

6067
let receivedString = try XCTUnwrap(String(data: receivedData, encoding: .utf8))
61-
XCTAssertEqual(receivedString, "abcdefghijklmnopqrstuvwxyz🔥") // no duplicates
68+
XCTAssertEqual(receivedString.count, testString.count * 128 * 128, "Corrupted or duplicated data")
6269
}
6370
}
6471

0 commit comments

Comments
 (0)