@@ -50,8 +50,8 @@ let testTimeout = DispatchTimeInterval.seconds(20)
5050let testResourcesPath = " ably-common/test-resources/ "
5151let echoServerAddress = " https://echo.ably.io/createJWT "
5252
53- func uniqueChannelName( prefix : String = " " ,
54- testIdentifier : String = #function ,
53+ func uniqueChannelName( for test : Test ,
54+ prefix : String = " " ,
5555 timestamp: TimeInterval = Date . timeIntervalSinceReferenceDate) -> String {
5656 let platform : String
5757#if targetEnvironment(macCatalyst)
@@ -67,7 +67,7 @@ func uniqueChannelName(prefix: String = "",
6767#else
6868 platform = " Unknown "
6969#endif
70- return " \( prefix) - \( platform) - \( testIdentifier . replacingOccurrences ( of : " () " , with : " " ) ) - \( timestamp) - \( NSUUID ( ) . uuidString) "
70+ return " \( prefix) - \( platform) - \( test . id ) - \( timestamp) - \( NSUUID ( ) . uuidString) "
7171}
7272
7373/// Common test utilities.
@@ -114,8 +114,8 @@ class AblyTests {
114114 return queue
115115 } ( )
116116
117- static func createUserQueue( ) -> DispatchQueue {
118- let queue = DispatchQueue ( label: " io.ably.tests.callbacks. \( UUID ( ) . uuidString) " , qos: . userInitiated)
117+ static func createUserQueue( for test : Test ) -> DispatchQueue {
118+ let queue = DispatchQueue ( label: " io.ably.tests.callbacks. \( test . id ) . \( UUID ( ) . uuidString) " , qos: . userInitiated)
119119 queue. setSpecific ( key: queueIdentityKey, value: QueueIdentity ( label: queue. label) )
120120 return queue
121121 }
@@ -124,9 +124,9 @@ class AblyTests {
124124 return DispatchQueue . getSpecific ( key: queueIdentityKey) ? . label
125125 }
126126
127- class func commonAppSetup( debug: Bool = false , forceNewApp: Bool = false ) throws -> ARTClientOptions {
128- let options = try AblyTests . clientOptions ( debug: debug)
129- options. testOptions. channelNamePrefix = " test- \( UUID ( ) . uuidString) "
127+ class func commonAppSetup( for test : Test , debug: Bool = false , forceNewApp: Bool = false ) throws -> ARTClientOptions {
128+ let options = try AblyTests . clientOptions ( for : test , debug: debug)
129+ options. testOptions. channelNamePrefix = " test- \( test . id ) - \( UUID ( ) . uuidString) "
130130
131131 if forceNewApp {
132132 testApplication = nil
@@ -161,7 +161,7 @@ class AblyTests {
161161 return options
162162 }
163163
164- class func clientOptions( debug: Bool = false , key: String ? = nil , requestToken: Bool = false ) throws -> ARTClientOptions {
164+ class func clientOptions( for test : Test , debug: Bool = false , key: String ? = nil , requestToken: Bool = false ) throws -> ARTClientOptions {
165165 let options = ARTClientOptions ( )
166166 options. environment = getEnvironment ( )
167167 if debug {
@@ -171,7 +171,7 @@ class AblyTests {
171171 options. key = key
172172 }
173173 if requestToken {
174- options. token = try getTestToken ( )
174+ options. token = try getTestToken ( for : test )
175175 }
176176 options. dispatchQueue = DispatchQueue . main
177177 options. internalDispatchQueue = queue
@@ -518,22 +518,22 @@ class PublishTestMessage {
518518}
519519
520520/// Access Token
521- func getTestToken( key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , file: FileString = #file, line: UInt = #line) throws -> String {
522- return try getTestTokenDetails ( key: key, clientId: clientId, capability: capability, ttl: ttl, file: file, line: line) . token
521+ func getTestToken( for test : Test , key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , file: FileString = #file, line: UInt = #line) throws -> String {
522+ return try getTestTokenDetails ( for : test , key: key, clientId: clientId, capability: capability, ttl: ttl, file: file, line: line) . token
523523}
524524
525- func getTestToken( key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , file: FileString = #file, line: UInt = #line, completion: @escaping ( Swift . Result < String , Error > ) -> Void ) {
526- getTestTokenDetails ( key: key, clientId: clientId, capability: capability, ttl: ttl) { result in
525+ func getTestToken( for test : Test , key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , file: FileString = #file, line: UInt = #line, completion: @escaping ( Swift . Result < String , Error > ) -> Void ) {
526+ getTestTokenDetails ( for : test , key: key, clientId: clientId, capability: capability, ttl: ttl) { result in
527527 completion ( result. map ( \. token) )
528528 }
529529}
530530
531531/// Access TokenDetails
532- func getTestTokenDetails( key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , completion: @escaping ( Swift . Result < ARTTokenDetails , Error > ) -> Void ) {
532+ func getTestTokenDetails( for test : Test , key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , completion: @escaping ( Swift . Result < ARTTokenDetails , Error > ) -> Void ) {
533533 let options : ARTClientOptions
534534 if let key = key {
535535 do {
536- options = try AblyTests . clientOptions ( )
536+ options = try AblyTests . clientOptions ( for : test )
537537 } catch {
538538 completion ( . failure( error) )
539539 return
@@ -542,7 +542,7 @@ func getTestTokenDetails(key: String? = nil, clientId: String? = nil, capability
542542 }
543543 else {
544544 do {
545- options = try AblyTests . commonAppSetup ( )
545+ options = try AblyTests . commonAppSetup ( for : test )
546546 } catch {
547547 completion ( . failure( error) )
548548 return
@@ -580,8 +580,8 @@ func getTestTokenDetails(key: String? = nil, clientId: String? = nil, capability
580580 }
581581}
582582
583- func getTestTokenDetails( key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , completion: @escaping ( ARTTokenDetails ? , Error ? ) -> Void ) {
584- getTestTokenDetails ( key: key, clientId: clientId, capability: capability, ttl: ttl, queryTime: queryTime) { result in
583+ func getTestTokenDetails( for test : Test , key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , completion: @escaping ( ARTTokenDetails ? , Error ? ) -> Void ) {
584+ getTestTokenDetails ( for : test , key: key, clientId: clientId, capability: capability, ttl: ttl, queryTime: queryTime) { result in
585585 switch result {
586586 case . success( let tokenDetails) :
587587 completion ( tokenDetails, nil )
@@ -591,18 +591,18 @@ func getTestTokenDetails(key: String? = nil, clientId: String? = nil, capability
591591 }
592592}
593593
594- func getTestTokenDetails( key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , file: FileString = #file, line: UInt = #line) throws -> ARTTokenDetails {
594+ func getTestTokenDetails( for test : Test , key: String ? = nil , clientId: String ? = nil , capability: String ? = nil , ttl: TimeInterval ? = nil , queryTime: Bool ? = nil , file: FileString = #file, line: UInt = #line) throws -> ARTTokenDetails {
595595 let result = try AblyTests . waitFor ( timeout: testTimeout, file: file, line: line) { value in
596- getTestTokenDetails ( key: key, clientId: clientId, capability: capability, ttl: ttl, queryTime: queryTime) { result in
596+ getTestTokenDetails ( for : test , key: key, clientId: clientId, capability: capability, ttl: ttl, queryTime: queryTime) { result in
597597 value ( result)
598598 }
599599 }
600600
601601 return try result. get ( )
602602}
603603
604- func getJWTToken( invalid: Bool = false , expiresIn: Int = 3600 , clientId: String = " testClientIDiOS " , capability: String = " { \" * \" :[ \" * \" ]} " , jwtType: String = " " , encrypted: Int = 0 ) throws -> String ? {
605- let options = try AblyTests . commonAppSetup ( )
604+ func getJWTToken( for test : Test , invalid: Bool = false , expiresIn: Int = 3600 , clientId: String = " testClientIDiOS " , capability: String = " { \" * \" :[ \" * \" ]} " , jwtType: String = " " , encrypted: Int = 0 ) throws -> String ? {
605+ let options = try AblyTests . commonAppSetup ( for : test )
606606 guard let components = options. key? . components ( separatedBy: " : " ) , let keyName = components. first, var keySecret = components. last else {
607607 fail ( " Invalid API key: \( options. key ?? " nil " ) " )
608608 return nil
@@ -628,8 +628,8 @@ func getJWTToken(invalid: Bool = false, expiresIn: Int = 3600, clientId: String
628628 return String ( data: responseData, encoding: String . Encoding. utf8)
629629}
630630
631- func getKeys( ) throws -> Dictionary < String , String > {
632- let options = try AblyTests . commonAppSetup ( )
631+ func getKeys( for test : Test ) throws -> Dictionary < String , String > {
632+ let options = try AblyTests . commonAppSetup ( for : test )
633633 guard let components = options. key? . components ( separatedBy: " : " ) , let keyName = components. first, let keySecret = components. last else {
634634 fatalError ( " Invalid API key) " )
635635 }
0 commit comments