Skip to content

Commit

Permalink
fix SoakTest
Browse files Browse the repository at this point in the history
  • Loading branch information
umair-ably committed Aug 5, 2024
1 parent 0d9af76 commit 699bfdf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
18 changes: 9 additions & 9 deletions Ably-SoakTest-AppUITests/SoakTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -91,7 +91,7 @@ struct SyncValue<T> {
}
}

func realtimeOperations(realtime: ARTRealtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) {
func realtimeOperations(realtime: Realtime, queue: DispatchQueue, shouldStop: @escaping () -> Bool) {
if shouldStop() {
return
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))")
Expand All @@ -206,7 +206,7 @@ func presenceCycle(channel: ARTRealtimeChannel, queue: DispatchQueue) {
}
}

extension ARTRealtimeChannels: Sequence {
extension RealtimeChannels: Sequence {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self.iterate())
}
Expand Down
4 changes: 2 additions & 2 deletions Ably-SoakTest-AppUITests/SoakTestReachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Ably-SoakTest-AppUITests/SoakTestURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -62,7 +62,7 @@ class SoakTestURLSession : NSObject, ARTURLSession {
}
}

class CancellableInQueue : NSObject, ARTCancellable {
class CancellableInQueue : NSObject, Cancellable {
let queue: DispatchQueue
var cancelled = false

Expand Down
40 changes: 19 additions & 21 deletions Ably-SoakTest-AppUITests/SoakTestWebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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)
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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
}
Expand All @@ -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()
)]
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ let package = Package(
.headerSearchPath("SocketRocket/Internal/Delegate"),
.headerSearchPath("SocketRocket/Internal/IOConsumer"),
]
),
.target(name: "Push", dependencies: ["Ably"], path: "PushSwift")
)
]
)

0 comments on commit 699bfdf

Please sign in to comment.