Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/no-connection…
Browse files Browse the repository at this point in the history
…-serial

# Conflicts:
#	Test/Tests/ARTDefaultTests.swift
  • Loading branch information
maratal committed Nov 11, 2023
2 parents d9d244c + 244dc3b commit 9cf3879
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 65 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [1.2.22](https://github.com/ably/ably-cocoa/tree/1.2.22)

[Full Changelog](https://github.com/ably/ably-cocoa/compare/1.2.21...1.2.22)

**Fixed issues:**

- Fixes an issue where certain errors will cause a Realtime connection to transition to `FAILED` when it should be transitioning to `DISCONNECTED` and retrying the connection attempt. [\#1817](https://github.com/ably/ably-cocoa/issues/1817)

## [1.2.21](https://github.com/ably/ably-cocoa/tree/1.2.21)

[Full Changelog](https://github.com/ably/ably-cocoa/compare/1.2.20...1.2.21)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You can install Ably for iOS and macOS through Package Manager, CocoaPods, Carth
- [This apple guide](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) explains the steps in more detail.
- To install the `ably-cocoa` package in another **Swift Package**, then add the following to your `Package.Swift`:
```swift
.package(url: "https://github.com/ably/ably-cocoa", from: "1.2.21"),
.package(url: "https://github.com/ably/ably-cocoa", from: "1.2.22"),
```
### Installing through [CocoaPods](https://cocoapods.org/)

Expand Down Expand Up @@ -101,7 +101,7 @@ If you see, for example, a `dyld: Library not loaded: @rpath/AblyDeltaCodec.fram

### Manual installation

1. Get the code from GitHub [from the release page](https://github.com/ably/ably-cocoa/releases/tag/1.2.21), or clone it to get the latest, unstable and possibly underdocumented version: `git clone git@github.com:ably/ably-cocoa.git`
1. Get the code from GitHub [from the release page](https://github.com/ably/ably-cocoa/releases/tag/1.2.22), or clone it to get the latest, unstable and possibly underdocumented version: `git clone git@github.com:ably/ably-cocoa.git`
2. Drag the directory `ably-cocoa/ably-cocoa` into your project as a group.
3. Ably depends on our [MessagePack Fork](https://github.com/ably-forks/msgpack-objective-C) 0.2.0; get it [from the releases page](https://github.com/ably-forks/msgpack-objective-C/releases/tag/0.2.0-ably-1) and link it into your project.

Expand Down
2 changes: 1 addition & 1 deletion Scripts/jazzy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jazzy \
--objc \
--clean \
--author Ably \
--module-version 1.2.21 \
--module-version 1.2.22 \
--umbrella-header Source/include/Ably/Ably.h \
--framework-root Source \
--module Ably \
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTClientInformation.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#import <sys/utsname.h>

NSString *const ARTClientInformationAgentNotVersioned = @"ARTClientInformationAgentNotVersioned";
NSString *const ARTClientInformation_libraryVersion = @"1.2.21";
NSString *const ARTClientInformation_libraryVersion = @"1.2.22";
static NSString *const _libraryName = @"ably-cocoa";

// NSOperatingSystemVersion has NSInteger as version components for some reason, so mitigate it here.
Expand Down
30 changes: 10 additions & 20 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -1638,21 +1638,10 @@ - (void)realtimeTransportFailed:(id<ARTRealtimeTransport>)transport withError:(A
return;
}
}

switch (transportError.type) {
case ARTRealtimeTransportErrorTypeBadResponse:
case ARTRealtimeTransportErrorTypeOther: {
ARTErrorInfo *const errorInfo = [ARTErrorInfo createFromNSError:transportError.error];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transition:ARTRealtimeFailed withMetadata:metadata];
break;
}
default: {
ARTErrorInfo *error = [ARTErrorInfo createFromNSError:transportError.error];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:error];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}
}

ARTErrorInfo *const errorInfo = [ARTErrorInfo createFromNSError:transportError.error];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}

- (void)realtimeTransportNeverConnected:(id<ARTRealtimeTransport>)transport {
Expand All @@ -1663,7 +1652,7 @@ - (void)realtimeTransportNeverConnected:(id<ARTRealtimeTransport>)transport {

ARTErrorInfo *const errorInfo = [ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport never connected"];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transition:ARTRealtimeFailed withMetadata:metadata];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}

- (void)realtimeTransportRefused:(id<ARTRealtimeTransport>)transport withError:(ARTRealtimeTransportError *)error {
Expand All @@ -1675,15 +1664,16 @@ - (void)realtimeTransportRefused:(id<ARTRealtimeTransport>)transport withError:(
if (error && error.type == ARTRealtimeTransportErrorTypeRefused) {
ARTErrorInfo *const errorInfo = [ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:[NSString stringWithFormat:@"Connection refused using %@", error.url]];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transition:ARTRealtimeFailed withMetadata:metadata];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}
else if (error) {
ARTErrorInfo *const errorInfo = [ARTErrorInfo createFromNSError:error.error];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transition:ARTRealtimeFailed withMetadata:metadata];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}
else {
[self transition:ARTRealtimeFailed withMetadata:[[ARTConnectionStateChangeMetadata alloc] init]];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] init];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}
}

Expand All @@ -1695,7 +1685,7 @@ - (void)realtimeTransportTooBig:(id<ARTRealtimeTransport>)transport {

ARTErrorInfo *const errorInfo = [ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport too big"];
ARTConnectionStateChangeMetadata *const metadata = [[ARTConnectionStateChangeMetadata alloc] initWithErrorInfo:errorInfo];
[self transition:ARTRealtimeFailed withMetadata:metadata];
[self transitionToDisconnectedOrSuspendedWithMetadata:metadata];
}

- (void)realtimeTransportSetMsgSerial:(id<ARTRealtimeTransport>)transport msgSerial:(int64_t)msgSerial {
Expand Down
18 changes: 14 additions & 4 deletions Source/ARTWebSocketTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,30 @@ - (void)webSocket:(id<ARTWebSocket>)webSocket didCloseWithCode:(NSInteger)code r
[_delegate realtimeTransportDisconnected:self withError:nil];
break;
case ARTWsRefuse:
case ARTWsPolicyValidation:
[_delegate realtimeTransportRefused:self withError:[[ARTRealtimeTransportError alloc] initWithError:[ARTErrorInfo createWithCode:code message:reason] type:ARTRealtimeTransportErrorTypeRefused url:self.websocketURL]];
case ARTWsPolicyValidation: {
ARTErrorInfo *const errorInfo = [ARTErrorInfo createWithCode:code message:reason];
ARTRealtimeTransportError *const error = [[ARTRealtimeTransportError alloc] initWithError:errorInfo
type:ARTRealtimeTransportErrorTypeRefused
url:self.websocketURL];
[_delegate realtimeTransportRefused:self withError:error];
break;
}
case ARTWsTooBig:
[_delegate realtimeTransportTooBig:self];
break;
case ARTWsNoUtf8:
case ARTWsCloseProtocolError:
case ARTWsUnexpectedCondition:
case ARTWsExtension:
case ARTWsTlsError:
case ARTWsTlsError: {
// Failed
[_delegate realtimeTransportFailed:self withError:[[ARTRealtimeTransportError alloc] initWithError:[ARTErrorInfo createWithCode:code message:reason] type:ARTRealtimeTransportErrorTypeOther url:self.websocketURL]];
ARTErrorInfo *const errorInfo = [ARTErrorInfo createWithCode:code message:reason];
ARTRealtimeTransportError *const error = [[ARTRealtimeTransportError alloc] initWithError:errorInfo
type:ARTRealtimeTransportErrorTypeOther
url:self.websocketURL];
[_delegate realtimeTransportFailed:self withError:error];
break;
}
default:
NSAssert(true, @"WebSocket close: unknown code");
break;
Expand Down
3 changes: 3 additions & 0 deletions Source/PrivateHeaders/Ably/ARTRealtimeTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ typedef NS_ENUM(NSUInteger, ARTRealtimeTransportState) {

@property (nonatomic) NSError *error;
@property (nonatomic) ARTRealtimeTransportErrorType type;
/**
This meaning of this property is only defined if the error is of type `ARTRealtimeTransportErrorTypeBadResponse`.
*/
@property (nonatomic) NSInteger badResponseCode;
@property (nonatomic) NSURL *url;

Expand Down
18 changes: 14 additions & 4 deletions Test/Test Utilities/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ enum FakeNetworkResponse {
case requestTimeout(timeout: TimeInterval)
case hostInternalError(code: Int)
case host400BadRequest
case arbitraryError

var error: NSError {
switch self {
Expand All @@ -765,6 +766,8 @@ enum FakeNetworkResponse {
return NSError(domain: AblyTestsErrorDomain, code: code, userInfo: [NSLocalizedDescriptionKey: "internal error", NSLocalizedFailureReasonErrorKey: AblyTestsErrorDomain + ".FakeNetworkResponse"])
case .host400BadRequest:
return NSError(domain: AblyTestsErrorDomain, code: 400, userInfo: [NSLocalizedDescriptionKey: "bad request", NSLocalizedFailureReasonErrorKey: AblyTestsErrorDomain + ".FakeNetworkResponse"])
case .arbitraryError:
return NSError(domain: AblyTestsErrorDomain, code: 1, userInfo: [NSLocalizedDescriptionKey: "error from FakeNetworkResponse.arbitraryError"])
}
}

Expand All @@ -780,6 +783,8 @@ enum FakeNetworkResponse {
return ARTRealtimeTransportError(error: error, badResponseCode: code, url: url)
case .host400BadRequest:
return ARTRealtimeTransportError(error: error, badResponseCode: 400, url: url)
case .arbitraryError:
return ARTRealtimeTransportError(error: error, type: .other, url: url)
}
}
}
Expand Down Expand Up @@ -865,6 +870,8 @@ class MockHTTP: ARTHttp {
requestCallback?(HTTPURLResponse(url: URL(string: "http://cocoa.test.suite")!, statusCode: code, httpVersion: nil, headerFields: nil), nil, nil)
case .host400BadRequest:
requestCallback?(HTTPURLResponse(url: URL(string: "http://cocoa.test.suite")!, statusCode: 400, httpVersion: nil, headerFields: nil), nil, nil)
case .arbitraryError:
requestCallback?(nil, nil, NSError(domain: AblyTestsErrorDomain, code: 1, userInfo: [NSLocalizedDescriptionKey: "error from FakeNetworkResponse.arbitraryError"]))
}
}

Expand Down Expand Up @@ -1300,7 +1307,8 @@ class TestProxyTransport: ARTWebSocketTransport {
case .noInternet,
.hostUnreachable,
.hostInternalError,
.host400BadRequest:
.host400BadRequest,
.arbitraryError:
performFakeConnectionError(0.1, error: networkResponse.transportError(for: url))
case .requestTimeout(let timeout):
performFakeConnectionError(0.1 + timeout, error: networkResponse.transportError(for: url))
Expand Down Expand Up @@ -1688,9 +1696,11 @@ extension ARTWebSocketTransport {
}

func simulateIncomingError() {
let error = NSError(domain: ARTAblyErrorDomain, code: 0, userInfo: [NSLocalizedDescriptionKey:"Fail test"])
let webSocketDelegate = self as ARTWebSocketDelegate
webSocketDelegate.webSocket?(self.websocket!, didFailWithError: error)
// Simulate receiving an ERROR ProtocolMessage, which should put a client into the FAILED state (per RTN15i)
let protocolMessage = ARTProtocolMessage()
protocolMessage.action = .error
protocolMessage.error = ARTErrorInfo.create(withCode: 50000 /* arbitrarily chosen */, message: "Fail test")
receive(protocolMessage)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Test/Tests/ARTDefaultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Ably.ARTDefault // System under Test
class ARTDefaultTests: XCTestCase {

func testVersions() {
XCTAssertEqual(ARTDefault.apiVersion(), "2")
XCTAssertEqual(ARTDefault.libraryVersion(), "1.2.21")
XCTAssertEqual(ARTDefault.apiVersion(), "1.2")
XCTAssertEqual(ARTDefault.libraryVersion(), "1.2.22")
}
}
6 changes: 3 additions & 3 deletions Test/Tests/ClientInformationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class ClientInformationTests: XCTestCase {

XCTAssertEqual(agents.keys.count, 2)

XCTAssertEqual(agents["ably-cocoa"], "1.2.21")
XCTAssertEqual(agents["ably-cocoa"], "1.2.22")

#if os(iOS)
XCTAssertTrue(agents.keys.contains("iOS"))
Expand All @@ -27,7 +27,7 @@ final class ClientInformationTests: XCTestCase {
// CR3, CR3b
func testAgentIdentifierWithAdditionalAgents_withNilAdditionalAgents() {
let expectedIdentifier = [
"ably-cocoa/1.2.21",
"ably-cocoa/1.2.22",
ARTDefault.platformAgent()
].sorted().joined(separator: " ")

Expand All @@ -42,7 +42,7 @@ final class ClientInformationTests: XCTestCase {
]

let expectedIdentifier = [
"ably-cocoa/1.2.21",
"ably-cocoa/1.2.22",
"demolib/0.0.1",
"morelib",
ARTDefault.platformAgent()
Expand Down
Loading

0 comments on commit 9cf3879

Please sign in to comment.