From 699bfdf0ed95ed26b98d4047b745458f6d82c647 Mon Sep 17 00:00:00 2001 From: Umair Date: Mon, 5 Aug 2024 14:50:08 +0100 Subject: [PATCH] fix SoakTest --- Ably-SoakTest-AppUITests/SoakTest.swift | 18 ++++----- .../SoakTestReachability.swift | 4 +- .../SoakTestURLSession.swift | 6 +-- .../SoakTestWebSocket.swift | 40 +++++++++---------- Package.swift | 3 +- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/Ably-SoakTest-AppUITests/SoakTest.swift b/Ably-SoakTest-AppUITests/SoakTest.swift index bb840073e..504e1feff 100644 --- a/Ably-SoakTest-AppUITests/SoakTest.swift +++ b/Ably-SoakTest-AppUITests/SoakTest.swift @@ -29,11 +29,11 @@ class SoakTest: XCTestCase { let internalQueue = DispatchQueue(label: "io.ably.soakTest.internal.\(i)") queue.async { - let options: ARTClientOptions = { + let options: ClientOptions = { if true.times(1, outOf: 2) { - return ARTClientOptions(key: "fake:key") + return ClientOptions(key: "fake:key") } else { - let options = ARTClientOptions() + let options = ClientOptions() options.authUrl = NSURL(string: "http://fakeauth.com") as URL? return options } @@ -43,11 +43,11 @@ class SoakTest: XCTestCase { options.dispatchQueue = queue options.internalDispatchQueue = internalQueue options.testOptions.transportFactory = SoakTestRealtimeTransportFactory() - let realtime = ARTRealtime(options: options) + let realtime = Realtime(options: options) realtime.internal.setReachabilityClass(SoakTestReachability.self) realtime.connection.on { state in - print("got connection notification; error: \(String(describing: state?.reason))") + print("got connection notification; error: \(String(describing: state.reason))") } realtimeOperations(realtime: realtime, queue: queue, shouldStop: shouldStop.get) @@ -91,7 +91,7 @@ struct SyncValue { } } -func realtimeOperations(realtime: ARTRealtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) { +func realtimeOperations(realtime: Realtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) { if shouldStop() { return } @@ -119,7 +119,7 @@ func realtimeOperations(realtime: ARTRealtime, queue: DispatchQueue, shouldStop: } } -func channelsOperations(realtime: ARTRealtime, queue: DispatchQueue) { +func channelsOperations(realtime: Realtime, queue: DispatchQueue) { queue.afterSeconds(between: 0.1 ... 1.0) { if realtime.connection.state == .closed { return @@ -180,7 +180,7 @@ func channelsOperations(realtime: ARTRealtime, queue: DispatchQueue) { } } -func presenceCycle(channel: ARTRealtimeChannel, queue: DispatchQueue) { +func presenceCycle(channel: RealtimeChannel, queue: DispatchQueue) { let client = "presenceClient.\(nextGlobalSerial())" channel.presence.enterClient(client, data: randomMessageData()) { error in print("\(channel.name): got enter ack; error: \(String(describing: error))") @@ -206,7 +206,7 @@ func presenceCycle(channel: ARTRealtimeChannel, queue: DispatchQueue) { } } -extension ARTRealtimeChannels: Sequence { +extension RealtimeChannels: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(self.iterate()) } diff --git a/Ably-SoakTest-AppUITests/SoakTestReachability.swift b/Ably-SoakTest-AppUITests/SoakTestReachability.swift index 55a438dbf..bffb340c5 100644 --- a/Ably-SoakTest-AppUITests/SoakTestReachability.swift +++ b/Ably-SoakTest-AppUITests/SoakTestReachability.swift @@ -13,8 +13,8 @@ class SoakTestReachability : NSObject, ARTReachability { let queue: DispatchQueue var callback: ((Bool) -> Void)? var isReachable = true - - required init(logger: ARTLog, queue: DispatchQueue) { + + required init(logger: InternalLog, queue: DispatchQueue) { self.queue = queue super.init() waitAndToggle() diff --git a/Ably-SoakTest-AppUITests/SoakTestURLSession.swift b/Ably-SoakTest-AppUITests/SoakTestURLSession.swift index 5c28f6094..f89208454 100644 --- a/Ably-SoakTest-AppUITests/SoakTestURLSession.swift +++ b/Ably-SoakTest-AppUITests/SoakTestURLSession.swift @@ -11,13 +11,13 @@ import Ably.Private class SoakTestURLSession : NSObject, ARTURLSession { let queue: DispatchQueue - var cancellables: [ARTCancellable] = [] + var cancellables: [Cancellable] = [] required init(_ queue: DispatchQueue) { self.queue = queue } - func get(_ request: URLRequest, completion callback: @escaping (HTTPURLResponse?, Data?, Error?) -> Void) -> ARTCancellable & NSObjectProtocol { + func get(_ request: URLRequest, completion callback: @escaping (HTTPURLResponse?, Data?, Error?) -> Void) -> Cancellable & NSObjectProtocol { let cancellable = CancellableInQueue(queue: queue) cancellables.append(cancellable) @@ -62,7 +62,7 @@ class SoakTestURLSession : NSObject, ARTURLSession { } } -class CancellableInQueue : NSObject, ARTCancellable { +class CancellableInQueue : NSObject, Cancellable { let queue: DispatchQueue var cancelled = false diff --git a/Ably-SoakTest-AppUITests/SoakTestWebSocket.swift b/Ably-SoakTest-AppUITests/SoakTestWebSocket.swift index ec7cd4c04..ce0d05e82 100644 --- a/Ably-SoakTest-AppUITests/SoakTestWebSocket.swift +++ b/Ably-SoakTest-AppUITests/SoakTestWebSocket.swift @@ -15,12 +15,11 @@ class SoakTestWebSocketFactory: WebSocketFactory { } class SoakTestRealtimeTransportFactory: RealtimeTransportFactory { - func transport(withRest rest: ARTRestInternal, options: ARTClientOptions, resumeKey: String?, connectionSerial: NSNumber?, logger: InternalLog) -> ARTRealtimeTransport { + func transport(withRest rest: ARTRestInternal, options: ClientOptions, resumeKey: String?, logger: InternalLog) -> ARTRealtimeTransport { return ARTWebSocketTransport( rest: rest, options: options, resumeKey: resumeKey, - connectionSerial: connectionSerial, logger: logger, webSocketFactory: SoakTestWebSocketFactory() ) @@ -44,7 +43,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { func open() { readyState = .connecting - delegateDispatchQueue!.afterSeconds(between: 0.1 ... ARTDefault.realtimeRequestTimeout() + 1.0) { + delegateDispatchQueue!.afterSeconds(between: 0.1 ... Default.realtimeRequestTimeout() + 1.0) { if true.times(9, outOf: 10) { self.readyState = .open self.delegate?.webSocketDidOpen?(self) @@ -68,7 +67,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { self.sendHeartbeats() } else { self.messageToClient(action: .error) { m in - m.error = ARTErrorInfo.create(from: fakeError) + m.error = ErrorInfo.create(from: fakeError) } } } @@ -97,15 +96,14 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { } } - func protocolMessage(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) -> ARTProtocolMessage { - return ARTProtocolMessage.build(action: action) { m in - m.connectionSerial = self.nextConnectionSerial() + func protocolMessage(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) -> ProtocolMessage { + return ProtocolMessage.build(action: action) { m in m.timestamp = Date() setUp(m) } } - func messageToClient(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) { + func messageToClient(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) { let message = protocolMessage(action: action, setUp: setUp) self.delegate?.webSocket?(self, didReceiveMessage: message) } @@ -139,7 +137,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { self.messageToClient(action: .nack) { m in m.msgSerial = self.pendingSerials.first! m.count = Int32(self.pendingSerials.count) - m.error = ARTErrorInfo.create(from: fakeError) + m.error = ErrorInfo.create(from: fakeError) } } self.pendingSerials.removeAll() @@ -170,7 +168,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { if true.times(1, outOf: 10) { self.messageToClient(action: .error) { m in m.channel = message.channel - m.error = ARTErrorInfo.create(from: fakeError) + m.error = ErrorInfo.create(from: fakeError) } return } @@ -201,7 +199,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { self.messageToClient(action: .detached) { m in m.channel = message.channel if true.times(1, outOf: 5) { - m.error = ARTErrorInfo.create(from: fakeError) + m.error = ErrorInfo.create(from: fakeError) } } @@ -224,7 +222,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { var serialForAttachedChannel: [String: Int64] = [:] - func nextMessageToClient(forChannel channel: String, action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void = { _ in }) { + func nextMessageToClient(forChannel channel: String, action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void = { _ in }) { guard var channelSerial = self.serialForAttachedChannel[channel] else { return } @@ -242,7 +240,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { doIfStillOpen(afterSecondsBetween: 0.1 ... 2.0) { self.nextMessageToClient(forChannel: channel, action: .message) { m in m.id = "message.\(nextGlobalSerial())" - m.messages = [ARTMessage( + m.messages = [Message( name: "fakeMessage", data: randomMessageData() )] @@ -254,7 +252,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { func sendPresenceMessages(channel: String) { doIfStillOpen(afterSecondsBetween: 0.1 ... 2.0) { - let presence = ARTPresenceMessage() + let presence = PresenceMessage() presence.clientId = "someone.\(nextGlobalSerial())" presence.data = randomMessageData() presence.action = .enter @@ -272,7 +270,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { func updatePresence(channel: String, clientId: String) { doIfStillOpen(afterSecondsBetween: 0.1 ... 10.0) { - let presence = ARTPresenceMessage() + let presence = PresenceMessage() presence.clientId = clientId if true.times(3, outOf: 4) { @@ -319,7 +317,7 @@ class SoakTestWebSocket: NSObject, ARTWebSocket { self.messageToClient(action: .sync) { m in m.channelSerial = "somethingsomething:\(cursor)" m.presence = page.map { member in - let message = ARTPresenceMessage() + let message = PresenceMessage() message.clientId = member message.action = .present return message @@ -351,8 +349,8 @@ extension String { let fakeError = "fake error for soak test".asError() -func authError() -> ARTErrorInfo { - return ARTErrorInfo.create(from: "fake auth error".asError(code: 40140)) +func authError() -> ErrorInfo { + return ErrorInfo.create(from: "fake auth error".asError(code: 40140)) } func serialSequence(label: String, first: Int64 = 0) -> (() -> Int64) { @@ -371,9 +369,9 @@ func serialSequence(label: String, first: Int64 = 0) -> (() -> Int64) { let nextGlobalSerial = serialSequence(label: "globalSerial") -extension ARTProtocolMessage { - class func build(action: ARTProtocolMessageAction, setUp: (ARTProtocolMessage) -> Void) -> ARTProtocolMessage { - let m = ARTProtocolMessage() +extension ProtocolMessage { + class func build(action: ProtocolMessageAction, setUp: (ProtocolMessage) -> Void) -> ProtocolMessage { + let m = ProtocolMessage() m.action = action m.id = "fakeProtocolMessage.\(nextGlobalSerial())" setUp(m) diff --git a/Package.swift b/Package.swift index 7fbe83b65..88bbabaae 100644 --- a/Package.swift +++ b/Package.swift @@ -47,8 +47,7 @@ let package = Package( .headerSearchPath("SocketRocket/Internal/Delegate"), .headerSearchPath("SocketRocket/Internal/IOConsumer"), ] - ), - .target(name: "Push", dependencies: ["Ably"], path: "PushSwift") + ) ] )