Skip to content

Commit

Permalink
Merge pull request #1863 from ably/transition-refactoring
Browse files Browse the repository at this point in the history
[SDK-4043] `transition:` method refactoring
  • Loading branch information
maratal authored Feb 23, 2024
2 parents b23b804 + db461a8 commit 821f6f1
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 276 deletions.
98 changes: 49 additions & 49 deletions Ably.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "ARTAttachRequestMetadata.h"
#import "ARTAttachRequestParams.h"

@implementation ARTAttachRequestMetadata
@implementation ARTAttachRequestParams

- (instancetype)initWithReason:(ARTErrorInfo *)reason {
return [self initWithReason:reason channelSerial:nil];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "ARTChannelStateChangeMetadata.h"
#import "ARTChannelStateChangeParams.h"

@implementation ARTChannelStateChangeMetadata
@implementation ARTChannelStateChangeParams

- (instancetype)initWithState:(ARTState)state {
return [self initWithState:state errorInfo:nil storeErrorInfo:NO];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "ARTConnectionStateChangeMetadata.h"
#import "ARTConnectionStateChangeParams.h"

@implementation ARTConnectionStateChangeMetadata
@implementation ARTConnectionStateChangeParams

- (instancetype)init {
return [self initWithErrorInfo:nil];
Expand Down
228 changes: 108 additions & 120 deletions Source/ARTRealtime.m

Large diffs are not rendered by default.

124 changes: 59 additions & 65 deletions Source/ARTRealtimeChannel.m

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Source/ARTTypes.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ - (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current previous:(AR
}

- (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current previous:(ARTRealtimeConnectionState)previous event:(ARTRealtimeConnectionEvent)event reason:(ARTErrorInfo *)reason retryIn:(NSTimeInterval)retryIn {
return [self initWithCurrent:current previous:previous event:event reason:reason retryIn:retryIn retryAttempt:nil resumed:NO];
return [self initWithCurrent:current previous:previous event:event reason:reason retryIn:retryIn retryAttempt:nil];
}

- (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current previous:(ARTRealtimeConnectionState)previous event:(ARTRealtimeConnectionEvent)event reason:(ARTErrorInfo *)reason retryIn:(NSTimeInterval)retryIn retryAttempt:(ARTRetryAttempt *)retryAttempt resumed:(BOOL)resumed {
- (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current previous:(ARTRealtimeConnectionState)previous event:(ARTRealtimeConnectionEvent)event reason:(ARTErrorInfo *)reason retryIn:(NSTimeInterval)retryIn retryAttempt:(ARTRetryAttempt *)retryAttempt {
self = [self init];
if (self) {
_current = current;
Expand All @@ -57,7 +57,6 @@ - (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current previous:(AR
_reason = reason;
_retryIn = retryIn;
_retryAttempt = retryAttempt;
_resumed = resumed;
}
return self;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Ably.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ framework module Ably {
header "ARTRetryDelayCalculator.h"
header "ARTBackoffRetryDelayCalculator.h"
header "ARTClientOptions+TestConfiguration.h"
header "ARTConnectionStateChangeMetadata.h"
header "ARTChannelStateChangeMetadata.h"
header "ARTAttachRequestMetadata.h"
header "ARTConnectionStateChangeParams.h"
header "ARTChannelStateChangeParams.h"
header "ARTAttachRequestParams.h"
header "ARTRetrySequence.h"
header "ARTTypes+Private.h"
header "ARTTestClientOptions.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
NS_ASSUME_NONNULL_BEGIN

/**
Provides metadata for a request to perform an operation that may ultimately call `ARTChannelRealtimeInternal`’s `internalAttach:callback:` method.
Provides parameters for a request to perform an operation that may ultimately call `ARTChannelRealtimeInternal`’s `internalAttach:callback:` method.
*/
NS_SWIFT_NAME(AttachRequestMetadata)
@interface ARTAttachRequestMetadata: NSObject
NS_SWIFT_NAME(AttachRequestParams)
@interface ARTAttachRequestParams: NSObject

/**
Information about the error that triggered this attach request, if any.
Expand All @@ -26,7 +26,7 @@ NS_SWIFT_NAME(AttachRequestMetadata)
- (instancetype)init NS_UNAVAILABLE;

/**
Creates an `ARTAttachRequestMetadata` instance with the given `reason`, whose `channelSerial` is `nil`.
Creates an `ARTAttachRequestParams` instance with the given `reason`, whose `channelSerial` is `nil`.
*/
- (instancetype)initWithReason:(nullable ARTErrorInfo *)reason;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
NS_ASSUME_NONNULL_BEGIN

/**
Provides metadata for a request to perform an operation that may cause an `ARTRealtimeChannelInternal` instance to emit a connection state change.
Provides parameters for a request to perform an operation that may cause an `ARTRealtimeChannelInternal` instance to emit a connection state change.
`ARTRealtimeChannelInternal` will incorporate some of this data into the `ARTChannelStateChange` object that it emits as a result of the connection state change.
*/
NS_SWIFT_NAME(ChannelStateChangeMetadata)
@interface ARTChannelStateChangeMetadata: NSObject
NS_SWIFT_NAME(ChannelStateChangeParams)
@interface ARTChannelStateChangeParams: NSObject

/**
A state that some operations will use when failing pending presence operations.
Expand All @@ -34,12 +34,12 @@ NS_SWIFT_NAME(ChannelStateChangeMetadata)
- (instancetype)init NS_UNAVAILABLE;

/**
Creates an `ARTChannelStateChangeMetadata` instance whose `errorInfo` is `nil`, and whose `storeErrorInfo` is `NO`.
Creates an `ARTChannelStateChangeParams` instance whose `errorInfo` is `nil`, and whose `storeErrorInfo` is `NO`.
*/
- (instancetype)initWithState:(ARTState)state;

/**
Creates an `ARTChannelStateChangeMetadata` instance with the given `errorInfo`, whose `storeErrorInfo` is `YES`.
Creates an `ARTChannelStateChangeParams` instance with the given `errorInfo`, whose `storeErrorInfo` is `YES`.
*/
- (instancetype)initWithState:(ARTState)state
errorInfo:(nullable ARTErrorInfo *)errorInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
NS_ASSUME_NONNULL_BEGIN

/**
Provides metadata for a request to perform an operation that may cause an `ARTRealtimeInternal` instance to emit a connection state change.
Provides parameters for a request to perform an operation that may cause an `ARTRealtimeInternal` instance to emit a connection state change.
`ARTRealtimeInternal` will incorporate this data into the `ARTConnectionStateChange` object that it emits as a result of the connection state change.
*/
NS_SWIFT_NAME(ConnectionStateChangeMetadata)
@interface ARTConnectionStateChangeMetadata: NSObject
NS_SWIFT_NAME(ConnectionStateChangeParams)
@interface ARTConnectionStateChangeParams: NSObject

/**
Information about the error that triggered this state change, if any.
Expand All @@ -23,7 +23,7 @@ NS_SWIFT_NAME(ConnectionStateChangeMetadata)
@property (assign, nonatomic) BOOL resumed;

/**
Creates an `ARTConnectionStateChangeMetadata` instance whose `errorInfo` is `nil`.
Creates an `ARTConnectionStateChangeParams` instance whose `errorInfo` is `nil`.
*/
- (instancetype)init;

Expand Down
14 changes: 7 additions & 7 deletions Source/PrivateHeaders/Ably/ARTRealtimeChannel+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

@class ARTProtocolMessage;
@class ARTRealtimePresenceInternal;
@class ARTChannelStateChangeMetadata;
@class ARTAttachRequestMetadata;
@class ARTChannelStateChangeParams;
@class ARTAttachRequestParams;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -51,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN

- (bool)isLastChannelSerial:(NSString *)channelSerial;

- (void)reattachWithMetadata:(ARTAttachRequestMetadata *)metadata;
- (void)reattachWithParams:(ARTAttachRequestParams *)params;

- (void)_attach:(nullable ARTCallback)callback;
- (void)_detach:(nullable ARTCallback)callback;
Expand All @@ -65,7 +65,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARTRealtimeChannelInternal (Private)

- (void)transition:(ARTRealtimeChannelState)state withMetadata:(ARTChannelStateChangeMetadata *)metadata;
- (void)performTransitionToState:(ARTRealtimeChannelState)state withParams:(ARTChannelStateChangeParams *)params;

- (void)onChannelMessage:(ARTProtocolMessage *)message;
- (void)publishProtocolMessage:(ARTProtocolMessage *)pm callback:(ARTStatusCallback)cb;
Expand All @@ -78,12 +78,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)onSync:(ARTProtocolMessage *)message;
- (void)onError:(ARTProtocolMessage *)error;

- (void)setSuspended:(ARTChannelStateChangeMetadata *)metadata;
- (void)setFailed:(ARTChannelStateChangeMetadata *)metadata;
- (void)setSuspended:(ARTChannelStateChangeParams *)params;
- (void)setFailed:(ARTChannelStateChangeParams *)params;
- (void)throwOnDisconnectedOrFailed;

- (void)broadcastPresence:(ARTPresenceMessage *)pm;
- (void)detachChannel:(ARTChannelStateChangeMetadata *)metadata;
- (void)detachChannel:(ARTChannelStateChangeParams *)params;

- (void)sync;
- (void)sync:(nullable ARTCallback)callback;
Expand Down
8 changes: 1 addition & 7 deletions Source/PrivateHeaders/Ably/ARTTypes+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, readonly, nullable) ARTRetryAttempt *retryAttempt;

/**
* Indicates whether the connection was resumed.
*/
@property (assign, nonatomic) BOOL resumed;

- (instancetype)initWithCurrent:(ARTRealtimeConnectionState)current
previous:(ARTRealtimeConnectionState)previous
event:(ARTRealtimeConnectionEvent)event
reason:(nullable ARTErrorInfo *)reason
retryIn:(NSTimeInterval)retryIn
retryAttempt:(nullable ARTRetryAttempt *)retryAttempt
resumed:(BOOL)resumed;
retryAttempt:(nullable ARTRetryAttempt *)retryAttempt;

@end

Expand Down
3 changes: 1 addition & 2 deletions Test/Tests/RealtimeClientConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5129,6 +5129,7 @@ class RealtimeClientConnectionTests: XCTestCase {
fail("Reason error is nil"); done(); return
}
XCTAssertEqual(error.code, 1234)
XCTAssertEqual(client.connection.errorReason?.code, 1234)
XCTAssertEqual(client.connection.state, ARTRealtimeConnectionState.connected)
XCTAssertEqual(stateChange.current, ARTRealtimeConnectionState.connected)
XCTAssertEqual(stateChange.current, stateChange.previous)
Expand All @@ -5139,8 +5140,6 @@ class RealtimeClientConnectionTests: XCTestCase {
connectedMessageWithError.error = ARTErrorInfo.create(withCode: 1234, message: "fabricated error")
client.internal.transport?.receive(connectedMessageWithError)
}

XCTAssertNil(client.connection.errorReason)
}

// https://github.com/ably/ably-cocoa/issues/454
Expand Down
3 changes: 2 additions & 1 deletion Test/Tests/RealtimeClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class RealtimeClientTests: XCTestCase {
func test__019__RealtimeClient__options__url_should_contains_transport_params() throws {
let test = Test()
let options = try AblyTests.commonAppSetup(for: test)
options.autoConnect = false
options.transportParams = [
"tpBool": .init(bool: true),
"tpInt": .init(number: .init(value: 12)),
Expand All @@ -211,7 +212,7 @@ class RealtimeClientTests: XCTestCase {
let client = ARTRealtime(options: options)
defer { client.dispose(); client.close() }

waitUntil(timeout: testTimeout.multiplied(by: 2)) { done in
waitUntil(timeout: testTimeout) { done in
client.connection.once(.connecting) { _ in
guard let webSocketTransport = client.internal.transport as? ARTWebSocketTransport else {
fail("Transport should be of type ARTWebSocketTransport"); done()
Expand Down

0 comments on commit 821f6f1

Please sign in to comment.