Skip to content

Commit

Permalink
Fix legacy tests: account blocked (connection limits exceeded) (#505)
Browse files Browse the repository at this point in the history
* Test suite: add `testSuite_waitForConnectionToClose`

* Fix testMultipleText_1000_10: increase timeout

* Fix connection broken after connection is closed: should wait for the publishing acknowledgement

* Fix spec failures (#506)

* Test suite: add `testSuite_waitForConnectionToClose`

* Fix testMultipleText_1000_10: increase timeout

* A few fixes in tests.

* Fix connection broken after connection is closed: should wait for the publishing acknowledgement

* Fix spec tests: expects `done` completion closure to only be called once

* Fix: decode each REST presence message data

* Fix RSP5

* Fix: should error if authUrl request is returning incompatible data

* Fix RTP8h, RTP9e, RTP10e: token with clientId

* Fix RTN17e: already closed

* RTC8: pending

* Fix #117 test: add delay

* Enhance RTP5b: wait for presence of Client2

 - sometimes was passing, sometimes not

* Fix InvalidNimbleAPIUsage: nested async expectations are not allowed to avoid creating flaky tests
  • Loading branch information
ricardopereira authored Sep 27, 2016
1 parent 4593352 commit 13fcb23
Show file tree
Hide file tree
Showing 24 changed files with 437 additions and 234 deletions.
6 changes: 6 additions & 0 deletions Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
D7588AF41BFF91B800BB8279 /* ARTURLSessionServerTrust.m in Sources */ = {isa = PBXBuildFile; fileRef = D7588AF21BFF91B800BB8279 /* ARTURLSessionServerTrust.m */; };
D77394031C6F6FFE00F5478F /* ARTProtocolMessage+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D77394021C6F6FFE00F5478F /* ARTProtocolMessage+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
D780846E1C68B3E50083009D /* NSObject+TestSuite.m in Sources */ = {isa = PBXBuildFile; fileRef = D780846D1C68B3E50083009D /* NSObject+TestSuite.m */; };
D79FF2751D901CD50067FA6A /* ARTRealtime+TestSuite.m in Sources */ = {isa = PBXBuildFile; fileRef = D79FF2741D901CD50067FA6A /* ARTRealtime+TestSuite.m */; };
D7B17EE31C07208B00A6958E /* ARTConnectionDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = D7B17EE11C07208B00A6958E /* ARTConnectionDetails.h */; settings = {ATTRIBUTES = (Public, ); }; };
D7B17EE41C07208B00A6958E /* ARTConnectionDetails.m in Sources */ = {isa = PBXBuildFile; fileRef = D7B17EE21C07208B00A6958E /* ARTConnectionDetails.m */; };
D7C1B8771BBEA81A0087B55F /* Auth.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C1B8761BBEA81A0087B55F /* Auth.swift */; };
Expand Down Expand Up @@ -361,6 +362,8 @@
D77394021C6F6FFE00F5478F /* ARTProtocolMessage+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ARTProtocolMessage+Private.h"; sourceTree = "<group>"; };
D780846C1C68B3E50083009D /* NSObject+TestSuite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+TestSuite.h"; sourceTree = "<group>"; };
D780846D1C68B3E50083009D /* NSObject+TestSuite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+TestSuite.m"; sourceTree = "<group>"; };
D79FF2731D901CD50067FA6A /* ARTRealtime+TestSuite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ARTRealtime+TestSuite.h"; sourceTree = "<group>"; };
D79FF2741D901CD50067FA6A /* ARTRealtime+TestSuite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ARTRealtime+TestSuite.m"; sourceTree = "<group>"; };
D7B17EE11C07208B00A6958E /* ARTConnectionDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ARTConnectionDetails.h; sourceTree = "<group>"; };
D7B17EE21C07208B00A6958E /* ARTConnectionDetails.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ARTConnectionDetails.m; sourceTree = "<group>"; };
D7C1B8761BBEA81A0087B55F /* Auth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Auth.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -464,6 +467,8 @@
1C1E52E81AB32E6E004A690F /* Realtime */ = {
isa = PBXGroup;
children = (
D79FF2731D901CD50067FA6A /* ARTRealtime+TestSuite.h */,
D79FF2741D901CD50067FA6A /* ARTRealtime+TestSuite.m */,
96E408351A38595F00087F77 /* ARTRealtimeAttachTest.m */,
1CC3D94A1AB6FBB60005BEB0 /* ARTRealtimeChannelHistoryTest.m */,
1C1E53011AB373C5004A690F /* ARTRealtimeChannelTest.m */,
Expand Down Expand Up @@ -1221,6 +1226,7 @@
1C1E53021AB373C5004A690F /* ARTRealtimeChannelTest.m in Sources */,
1CC3D9571AB700EC0005BEB0 /* ARTRealtimeMessageTest.m in Sources */,
1C1E52F21AB32ED1004A690F /* ARTRestChannelPublishTest.m in Sources */,
D79FF2751D901CD50067FA6A /* ARTRealtime+TestSuite.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ - (void)handleAuthUrlResponse:(NSHTTPURLResponse *)response withData:(NSData *)d
ARTTokenRequest *tokenRequest = [_rest.encoders[@"application/json"] decodeTokenRequest:data error:&decodeError];
if (decodeError) {
callback(nil, decodeError);
} else {
} else if (tokenRequest) {
[tokenRequest toTokenDetails:self callback:callback];
} else {
callback(nil, [ARTErrorInfo createWithCode:ARTStateAuthUrlIncompatibleContent message:@"content response cannot be used for token request"]);
}
} else {
callback(tokenDetails, nil);
Expand Down
10 changes: 9 additions & 1 deletion Source/ARTRestPresence.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ - (BOOL)history:(ARTDataQuery *)query callback:(void(^)(__GENERIC(ARTPaginatedRe

ARTPaginatedResultResponseProcessor responseProcessor = ^(NSHTTPURLResponse *response, NSData *data) {
id<ARTEncoder> encoder = [_channel.rest.encoders objectForKey:response.MIMEType];
return [encoder decodePresenceMessages:data];
return [[encoder decodePresenceMessages:data] artMap:^(ARTPresenceMessage *message) {
NSError *error;
message = [message decodeWithEncoder:_channel.dataEncoder error:&error];
if (error != nil) {
ARTErrorInfo *errorInfo = [ARTErrorInfo wrap:(ARTErrorInfo *)error.userInfo[NSLocalizedFailureReasonErrorKey] prepend:@"Failed to decode data: "];
[_channel.logger error:@"RS:%p %@", _channel.rest, errorInfo.message];
}
return message;
}];
};

[ARTPaginatedResult executePaginated:_channel.rest withRequest:request andResponseProcessor:responseProcessor callback:callback];
Expand Down
1 change: 1 addition & 0 deletions Source/ARTStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef NS_ENUM(NSUInteger, ARTState) {
ARTStateNoClientId,
ARTStateMismatchedClientId,
ARTStateRequestTokenFailed,
ARTStateAuthUrlIncompatibleContent,
ARTStateBadConnectionState,
ARTStateError = 99999
};
Expand Down
10 changes: 7 additions & 3 deletions Spec/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Auth : QuickSpec {
options.autoConnect = false

let client = ARTRealtime(options: options)
defer { client.close() }
defer { client.dispose(); client.close() }
client.setTransportClass(TestProxyTransport.self)
client.connect()

Expand Down Expand Up @@ -1893,6 +1893,10 @@ class Auth : QuickSpec {
// Invalid TokenDetails
waitUntil(timeout: testTimeout) { done in
ARTRest(options: options).auth.authorise(nil, options: nil) { tokenDetails, error in
guard let error = error else {
fail("Error is nil"); done(); return
}
expect(error.code).to(equal(Int(ARTState.AuthUrlIncompatibleContent.rawValue)))
expect(tokenDetails).to(beNil())
done()
}
Expand Down Expand Up @@ -2030,7 +2034,7 @@ class Auth : QuickSpec {

describe("Reauth") {
// RTC8
it("should use authorise({force: true}) to reauth with a token with a different set of capabilities") {
pending("should use authorise({force: true}) to reauth with a token with a different set of capabilities") {
// init ARTRest
let restOptions = AblyTests.setupOptions(AblyTests.jsonRestOptions)
let rest = ARTRest(options: restOptions)
Expand Down Expand Up @@ -2059,7 +2063,7 @@ class Auth : QuickSpec {
realtimeOptions.clientId = "testClientId"

let realtime = ARTRealtime(options:realtimeOptions)
defer { realtime.close() }
defer { realtime.dispose(); realtime.close() }

// wait for connected state
waitUntil(timeout: testTimeout) { done in
Expand Down
2 changes: 1 addition & 1 deletion Spec/RealtimeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RealtimeClient: QuickSpec {
// G4
it("All WebSocket connections should include the current API version") {
let client = AblyTests.newRealtime(AblyTests.commonAppSetup())
defer { client.close() }
defer { client.dispose(); client.close() }
let channel = client.channels.get("test")
waitUntil(timeout: testTimeout) { done in
channel.publish(nil, data: "message") { error in
Expand Down
Loading

0 comments on commit 13fcb23

Please sign in to comment.