Skip to content

Commit

Permalink
Merge pull request #1266 from ably/1265-updating-rest-channel-options…
Browse files Browse the repository at this point in the history
…-should-update-underlying-rest-channel

When setting realtime channel options, pass through to REST channel
  • Loading branch information
QuintinWillison authored Jan 20, 2022
2 parents 22b5782 + 71250a0 commit e2faf66
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ - (void)setOptions:(ARTRealtimeChannelOptions *_Nullable)options callback:(nulla

- (void)setOptions_nosync:(ARTRealtimeChannelOptions *_Nullable)options callback:(nullable ARTCallback)callback {
[self setOptions_nosync:options];
[self.restChannel setOptions_nosync:options];

if (!options.modes && !options.params) {
if (callback)
Expand Down
2 changes: 1 addition & 1 deletion Spec/Test Utilities/NSObject+TestSuite.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation NSObject (TestSuite)
return [self aspect_hookSelector:selector withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info) {
__autoreleasing id arg;
[[info originalInvocation] getArgument:&arg atIndex:2+index];
callback([arg copy]);
callback(arg);
} error:nil];
}

Expand Down
33 changes: 33 additions & 0 deletions Spec/Tests/RealtimeClientChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4188,6 +4188,39 @@ class RealtimeClientChannelTests: XCTestCase {
expect(lastAttach.flags & subscribeFlag).to(equal(subscribeFlag))
expect(lastAttach.params).to(equal(channelOptions.params))
}

func test__Channel_options__setOptions__shouldUpdateOptionsOfRestChannel() {
let client = AblyTests.newRealtime(AblyTests.commonAppSetup())
defer { client.dispose(); client.close() }
let channel = client.channels.get("foo")

waitUntil(timeout: testTimeout) { done in
client.connection.once(.connected) { _ in
done()
}
}

var restChannelSetOptions: ARTChannelOptions?
let token = channel.internal.restChannel.testSuite_getArgument(from: #selector(ARTRestChannelInternal.setOptions_nosync(_:)), at: 0) { arg in
guard let optionsArg = arg as? ARTChannelOptions else {
XCTFail("Expected setOptions: to have been called with an ARTChannelOptions instance")
return
}
restChannelSetOptions = optionsArg
}
defer { token.remove() }

let channelOptions = ARTRealtimeChannelOptions(cipherKey: ARTCrypto.generateRandomKey() as NSData)

waitUntil(timeout: testTimeout) { done in
channel.setOptions(channelOptions) { error in
XCTAssertNil(error)
done()
}
}

expect(restChannelSetOptions).to(beIdenticalTo(channelOptions))
}

// RTL17
func test__122__Channel__history__should_not_emit_messages_to_subscribers_if_the_channel_is_in_any_state_other_than_ATTACHED() {
Expand Down

0 comments on commit e2faf66

Please sign in to comment.