@@ -21,39 +21,42 @@ import XCTest
2121class E2EEThreadTests : XCTestCase {
2222 // Attempt to crash LKRTCFrameCryptor initialization
2323 func testCreateFrameCryptor( ) async throws {
24+ // Create peerConnection
25+ let peerConnection = Engine . peerConnectionFactory. peerConnection ( with: . liveKitDefault( ) ,
26+ constraints: . defaultPCConstraints,
27+ delegate: nil )
28+
29+ let keyprovider = LKRTCFrameCryptorKeyProvider ( )
30+
2431 // Run Tasks concurrently
25- let result = try await withThrowingTaskGroup ( of: LKRTCFrameCryptor . self , returning : [ LKRTCFrameCryptor ] . self) { group in
26- for _ in 1 ... 10000 {
32+ try await withThrowingTaskGroup ( of: LKRTCFrameCryptor ? . self) { group in
33+ for _ in 1 ... 100 {
2734 group. addTask {
2835 let ns = UInt64 ( Double . random ( in: 1 ..< 3 ) * 1_000_000 )
2936 try await Task . sleep ( nanoseconds: ns)
3037
31- let pc = Engine . peerConnectionFactory. peerConnection ( with: . liveKitDefault( ) ,
32- constraints: . defaultPCConstraints,
33- delegate: nil )
34-
35- guard let transceiver = pc? . addTransceiver ( of: . audio) else {
38+ // Create a sender
39+ guard let sender = peerConnection? . addTransceiver ( of: . video) ? . sender else {
3640 XCTFail ( " Failed to create transceiver " )
37- throw fatalError ( )
41+ fatalError ( )
3842 }
3943
40- let keyprovider = LKRTCFrameCryptorKeyProvider ( )
44+ // Remove sender from pc
45+ peerConnection? . removeTrack ( sender)
4146
47+ // sender.track will be nil at this point.
48+ // Causing crashes in previous WebRTC versions. (patched in 114.5735.19)
4249 return LKRTCFrameCryptor ( factory: Engine . peerConnectionFactory,
43- rtpReceiver : transceiver . receiver ,
50+ rtpSender : sender ,
4451 participantId: " dummy " ,
45- algorithm: RTCCyrptorAlgorithm . aesGcm,
52+ algorithm: . aesGcm,
4653 keyProvider: keyprovider)
4754 }
4855 }
4956
50- var result : [ LKRTCFrameCryptor ] = [ ]
51- for try await e in group {
52- result. append ( e)
53- }
54- return result
57+ try await group. waitForAll ( )
5558 }
5659
57- print ( " frameCryptors: \( result ) " )
60+ peerConnection ? . close ( )
5861 }
5962}
0 commit comments