Skip to content

Commit

Permalink
Got back resumed property in ARTChannelStateChangeParams along wi…
Browse files Browse the repository at this point in the history
…th the removed test (for RTL2f).
  • Loading branch information
maratal committed May 19, 2024
1 parent 465184b commit 982ae37
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ - (void)emit:(ARTChannelEvent)event with:(ARTChannelStateChange *)data {

- (void)performTransitionToState:(ARTRealtimeChannelState)state withParams:(ARTChannelStateChangeParams *)params {
ARTLogDebug(self.logger, @"RT:%p C:%p (%@) channel state transitions from %tu - %@ to %tu - %@%@", _realtime, self, self.name, self.state_nosync, ARTRealtimeChannelStateToStr(self.state_nosync), state, ARTRealtimeChannelStateToStr(state), params.retryAttempt ? [NSString stringWithFormat: @" (result of %@)", params.retryAttempt.id] : @"");
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:state previous:self.state_nosync event:(ARTChannelEvent)state reason:params.errorInfo resumed:NO retryAttempt:params.retryAttempt];
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:state previous:self.state_nosync event:(ARTChannelEvent)state reason:params.errorInfo resumed:params.resumed retryAttempt:params.retryAttempt];
self.state = state;

if (params.storeErrorInfo) {
Expand Down Expand Up @@ -680,6 +680,7 @@ - (void)setAttached:(ARTProtocolMessage *)message {
} else {
params = [[ARTChannelStateChangeParams alloc] initWithState:ARTStateOk];
}
params.resumed = message.resumed;
[self performTransitionToState:ARTRealtimeChannelAttached withParams:params];
[self.presence onAttached:message];
[_attachedEventEmitter emit:nil with:nil];
Expand Down
5 changes: 5 additions & 0 deletions Source/PrivateHeaders/Ably/ARTChannelStateChangeParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ NS_SWIFT_NAME(ChannelStateChangeParams)

@property (nullable, nonatomic, readonly) ARTRetryAttempt *retryAttempt;

/**
The `resumed` value of the `ARTProtocolMessage` that triggered this state change.
*/
@property (nonatomic) BOOL resumed;

- (instancetype)init NS_UNAVAILABLE;

/**
Expand Down
49 changes: 48 additions & 1 deletion Test/Tests/RealtimeClientChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,55 @@ class RealtimeClientChannelTests: XCTestCase {
}
}

// TODO: RTL2f
// RTL2f (connection resumption case)
func test__011__Channel__EventEmitter__channel_states_and_events__ChannelStateChange_will_contain_a_resumed_boolean_attribute_with_value__true__if_the_bit_flag_RESUMED_was_included() throws {
let test = Test()
let options = try AblyTests.commonAppSetup(for: test)
options.testOptions.transportFactory = TestProxyTransportFactory()
options.tokenDetails = try getTestTokenDetails(for: test, ttl: 5.0)
let client = ARTRealtime(options: options)
defer { client.dispose(); client.close() }
let channel = client.channels.get(test.uniqueChannelName())

waitUntil(timeout: testTimeout) { done in
let partialDone = AblyTests.splitDone(4, done: done)
channel.on { stateChange in
switch stateChange.current {
case .attached:
XCTAssertFalse(stateChange.resumed)
partialDone()
default:
XCTAssertFalse(stateChange.resumed)
}
}
client.connection.once(.disconnected) { stateChange in
channel.off()
guard let error = stateChange.reason else {
fail("Error is nil"); done(); return
}
XCTAssertEqual(error.code, ARTErrorCode.tokenExpired.intValue)
XCTAssertEqual(channel.state, ARTRealtimeChannelState.attached)
client.connection.once(.connected) { stateChange in
XCTAssertEqual(channel.state, ARTRealtimeChannelState.attaching)
partialDone()
}
channel.on { stateChange in
switch stateChange.current {
case .attached:
XCTAssertTrue(stateChange.resumed)
partialDone()
default:
XCTAssertFalse(stateChange.resumed)
}
}
partialDone()
}
channel.attach()
}
}

// TODO: RTL2f (connection recovery case)

// RTL3

// RTL3a
Expand Down

0 comments on commit 982ae37

Please sign in to comment.