Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTN15a #244

Merged
merged 3 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ably-ios/ARTRealtime+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ART_ASSUME_NONNULL_BEGIN
/// First `msgSerial` pending message.
@property (readwrite, assign, nonatomic) int64_t pendingMessageStartSerial;

/// Client is trying to resume the last connection
@property (readwrite, assign, nonatomic) BOOL resuming;

@property (nonatomic, copy, art_nullable) ARTRealtimePingCb pingCb;
@property (readonly, getter=getClientOptions) ARTClientOptions *options;

Expand Down
4 changes: 1 addition & 3 deletions ably-ios/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ - (void)failQueuedMessages:(ARTStatus *)error;

#pragma mark - ARTRealtime implementation

@implementation ARTRealtime {
BOOL _resuming;
}
@implementation ARTRealtime

- (instancetype)initWithKey:(NSString *)key {
return [self initWithOptions:[[ARTClientOptions alloc] initWithKey:key]];
Expand Down
62 changes: 61 additions & 1 deletion ablySpec/RealtimeClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class RealtimeClientConnection: QuickSpec {
delay(1.0) { done() }
}

client.simulateLostConnection()
client.simulateLostConnectionAndState()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see this is fixed in this PR so ignore my previous comment @ricardopereira, just working my way through the backlog...

expect(gotPublishedCallback).to(beFalse())
expect(client.connection.state).toEventually(equal(ARTRealtimeConnectionState.Connected), timeout: testTimeout)
expect(client.connection.id).toNot(equal(oldConnectionId))
Expand Down Expand Up @@ -1393,6 +1393,66 @@ class RealtimeClientConnection: QuickSpec {

}

// RTN15
context("connection failures once CONNECTED") {

// RTN15a
it("should not receive published messages until the connection reconnects successfully") {
let options = AblyTests.commonAppSetup()
options.autoConnect = false
options.disconnectedRetryTimeout = 1.0

let client1 = ARTRealtime(options: options)
defer { client1.close() }
let channel1 = client1.channels.get("test")

var states = [ARTRealtimeConnectionState]()
client1.connection.on() { stateChange in
states = states + [stateChange!.current]
}
client1.connect()

let client2 = ARTRealtime(options: options)
client2.connect()
defer { client2.close() }
let channel2 = client2.channels.get("test")

channel1.subscribe { message in
fail("Shouldn't receive the messsage")
}

expect(channel1.state).toEventually(equal(ARTRealtimeChannelState.Attached), timeout: testTimeout)

let firstConnection: (id: String, key: String) = (client1.connection.id!, client1.connection.key!)

// Connection state cannot be resumed
client1.simulateLostConnectionAndState()

channel2.publish(nil, data: "message") { errorInfo in
expect(errorInfo).to(beNil())
}

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connecting) { _ in
expect(client1.resuming).to(beTrue())
done()
}
}

waitUntil(timeout: testTimeout) { done in
client1.connection.once(.Connected) { _ in
expect(client1.resuming).to(beFalse())
expect(client1.connection.id).toNot(equal(firstConnection.id))
expect(client1.connection.key).toNot(equal(firstConnection.key))
done()
}
}

expect(states).to(equal([.Connecting, .Connected, .Disconnected, .Connecting, .Connected]))
}

}

// RTN18
context("state change side effects") {

Expand Down
2 changes: 1 addition & 1 deletion ablySpec/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ extension JSON {

extension ARTRealtime {

func simulateLostConnection() {
func simulateLostConnectionAndState() {
//1. Abruptly disconnect
//2. Change the `Connection#id` and `Connection#key` before the client
// library attempts to reconnect and resume the connection
Expand Down