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

[SDK-3926] Backport #1823 to fix/socketrocket-fix #1825

Closed
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/check-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
check:
runs-on: macos-latest
runs-on: macos-11
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: macos-latest
runs-on: macos-11

permissions:
deployments: write
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Integration Test: iOS 14.4"
name: "Integration Test: iOS 15.2"

on:
pull_request:
Expand All @@ -12,7 +12,7 @@ on:

jobs:
check:
runs-on: macos-10.15
runs-on: macos-11

env:
LC_CTYPE: en_US.UTF-8
Expand Down Expand Up @@ -47,11 +47,10 @@ jobs:

- name: Install Dependencies and Run Tests
run: |
brew install xcbeautify
make submodules
bundle install
make update_carthage_dependencies_ios
bundle exec fastlane test_iOS14_4
bundle exec fastlane test_iOS15_2

- name: Check Static Analyzer Output
id: analyzer-output
Expand All @@ -67,7 +66,7 @@ jobs:
if: ${{ failure() && steps.analyzer-output.outcome == 'failure' }}
uses: actions/upload-artifact@v2
with:
name: static-analyzer-reports-test_iOS14_4
name: static-analyzer-reports-test_iOS15_2
path: ./derived_data/**/report-*.html

# This is the script specified as the pod’s prepare_command in its Podspec.
Expand All @@ -82,7 +81,7 @@ jobs:
run: |
pod repo update
pod install
bundle exec fastlane scan -s Tests --output-directory "fastlane/test_output/examples/test_iOS14_4"
bundle exec fastlane scan -s Tests --output-directory "fastlane/test_output/examples/test_iOS15_2"

- name: Build APNS Example Project
working-directory: ./Examples/AblyPush
Expand All @@ -95,12 +94,6 @@ jobs:
with:
name: xcodebuild-logs
path: ~/Library/Developer/Xcode/DerivedData/*/Logs

- name: Upload test results to observability server
if: always()
env:
TEST_OBSERVABILITY_SERVER_AUTH_KEY: ${{ secrets.TEST_OBSERVABILITY_SERVER_AUTH_KEY }}
run: Scripts/upload_test_results.sh

- name: Swift Package Manager - Installation Test
working-directory: ./
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/integration-test-macOS10_15.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
check:
runs-on: macos-10.15
runs-on: macos-11

env:
LC_CTYPE: en_US.UTF-8
Expand Down Expand Up @@ -47,7 +47,6 @@ jobs:

- name: Install Dependencies and Run Tests
run: |
brew install xcbeautify
make submodules
bundle install
make update_carthage_dependencies_macos
Expand Down Expand Up @@ -90,12 +89,6 @@ jobs:
with:
name: xcodebuild-logs
path: ~/Library/Developer/Xcode/DerivedData/*/Logs

- name: Upload test results to observability server
if: always()
env:
TEST_OBSERVABILITY_SERVER_AUTH_KEY: ${{ secrets.TEST_OBSERVABILITY_SERVER_AUTH_KEY }}
run: Scripts/upload_test_results.sh

- name: Swift Package Manager - Installation Test
working-directory: ./
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Integration Test: tvOS 14.3"
name: "Integration Test: tvOS 15.2"

on:
pull_request:
Expand All @@ -12,7 +12,7 @@ on:

jobs:
check:
runs-on: macos-10.15
runs-on: macos-11

env:
LC_CTYPE: en_US.UTF-8
Expand Down Expand Up @@ -47,11 +47,10 @@ jobs:

- name: Install Dependencies and Run Tests
run: |
brew install xcbeautify
make submodules
bundle install
make update_carthage_dependencies_tvos
bundle exec fastlane test_tvOS14_3
bundle exec fastlane test_tvOS15_2

- name: Check Static Analyzer Output
id: analyzer-output
Expand All @@ -67,7 +66,7 @@ jobs:
if: ${{ failure() && steps.analyzer-output.outcome == 'failure' }}
uses: actions/upload-artifact@v2
with:
name: static-analyzer-reports-test_tvOS14_3
name: static-analyzer-reports-test_tvOS15_2
path: ./derived_data/**/report-*.html

# This is the script specified as the pod’s prepare_command in its Podspec.
Expand All @@ -90,12 +89,6 @@ jobs:
with:
name: xcodebuild-logs
path: ~/Library/Developer/Xcode/DerivedData/*/Logs

- name: Upload test results to observability server
if: always()
env:
TEST_OBSERVABILITY_SERVER_AUTH_KEY: ${{ secrets.TEST_OBSERVABILITY_SERVER_AUTH_KEY }}
run: Scripts/upload_test_results.sh

- name: Swift Package Manager - Installation Test
working-directory: ./
Expand Down
8 changes: 8 additions & 0 deletions Ably.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
21881E7A283BD08300CFD9E2 /* GCDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5A22171266F526600C87C42 /* GCDTests.swift */; };
21881E7B283BD0DF00CFD9E2 /* StringifiableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D520C4DD2680A1E3000012B2 /* StringifiableTests.swift */; };
21881E7C283BD0E100CFD9E2 /* StringifiableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D520C4DD2680A1E3000012B2 /* StringifiableTests.swift */; };
21D3CC572AF964AC00B3F2BD /* DataGatherer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D3CC562AF964AC00B3F2BD /* DataGatherer.swift */; };
21D3CC582AF964AC00B3F2BD /* DataGatherer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D3CC562AF964AC00B3F2BD /* DataGatherer.swift */; };
21D3CC592AF964AC00B3F2BD /* DataGatherer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21D3CC562AF964AC00B3F2BD /* DataGatherer.swift */; };
560579D924AF1BA900A4D03D /* ARTDefaultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560579D824AF1BA900A4D03D /* ARTDefaultTests.swift */; };
560579DA24AF1BA900A4D03D /* ARTDefaultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560579D824AF1BA900A4D03D /* ARTDefaultTests.swift */; };
560579DB24AF1BA900A4D03D /* ARTDefaultTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560579D824AF1BA900A4D03D /* ARTDefaultTests.swift */; };
Expand Down Expand Up @@ -1002,6 +1005,7 @@
217D181E25421FED00DFF07E /* ARTSRSecurityPolicy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTSRSecurityPolicy.m; sourceTree = "<group>"; };
217D181F25421FED00DFF07E /* ARTSRWebSocket.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTSRWebSocket.m; sourceTree = "<group>"; };
217D182025421FED00DFF07E /* ARTSRSecurityPolicy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ARTSRSecurityPolicy.h; sourceTree = "<group>"; };
21D3CC562AF964AC00B3F2BD /* DataGatherer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataGatherer.swift; sourceTree = "<group>"; };
560579D824AF1BA900A4D03D /* ARTDefaultTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ARTDefaultTests.swift; sourceTree = "<group>"; };
56190953238C3D3200A862A6 /* CryptoTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CryptoTest.m; sourceTree = "<group>"; };
841134772722205400CFA837 /* ARTArchiveTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ARTArchiveTests.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1499,6 +1503,7 @@
21BF060A2758477E00AE4C43 /* Test Utilities */ = {
isa = PBXGroup;
children = (
21D3CC562AF964AC00B3F2BD /* DataGatherer.swift */,
D7093CA8219EFA8A00723F17 /* MockDeviceStorage.swift */,
D780846C1C68B3E50083009D /* NSObject+TestSuite.h */,
D780846D1C68B3E50083009D /* NSObject+TestSuite.m */,
Expand Down Expand Up @@ -2653,6 +2658,7 @@
D777EEE820650ADF002EBA03 /* PushChannelTests.swift in Sources */,
D746AE2D1BBB625E003ECEF8 /* RestClientChannelsTests.swift in Sources */,
EBAB9A6F1C69702800AF036B /* ReadmeExamplesTests.swift in Sources */,
21D3CC572AF964AC00B3F2BD /* DataGatherer.swift in Sources */,
56190954238C3D3200A862A6 /* CryptoTest.m in Sources */,
D7C1B8771BBEA81A0087B55F /* AuthTests.swift in Sources */,
D7EBE5A31BE8391E0086E675 /* RealtimeClientConnectionTests.swift in Sources */,
Expand Down Expand Up @@ -2783,6 +2789,7 @@
D7093C1C219E466400723F17 /* ReadmeExamplesTests.swift in Sources */,
21881E7B283BD0DF00CFD9E2 /* StringifiableTests.swift in Sources */,
D7093C27219E466E00723F17 /* RealtimeClientChannelsTests.swift in Sources */,
21D3CC582AF964AC00B3F2BD /* DataGatherer.swift in Sources */,
848ED97426E50D0F0087E800 /* ObjcppTest.mm in Sources */,
D7093C28219E466E00723F17 /* RealtimeClientPresenceTests.swift in Sources */,
D7093C24219E466E00723F17 /* RealtimeClientTests.swift in Sources */,
Expand Down Expand Up @@ -2817,6 +2824,7 @@
D7093C71219EE25800723F17 /* NSObject+TestSuite.m in Sources */,
D7093C70219EE25400723F17 /* TestUtilities.swift in Sources */,
84569FA826B46F5100457CF5 /* ClientOptionsTests.swift in Sources */,
21D3CC592AF964AC00B3F2BD /* DataGatherer.swift in Sources */,
D7093C80219EE26400723F17 /* StatsTests.swift in Sources */,
D7093C77219EE26400723F17 /* RestClientChannelTests.swift in Sources */,
D520C4E32680A1FC000012B2 /* StringifiableTests.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ submodules:

## [Tests] Run tests on iOS 14.4 using sandbox environment
test_iOS:
ABLY_ENV="sandbox" NAME="ably-iOS" bundle exec fastlane test_iOS14_4
ABLY_ENV="sandbox" NAME="ably-iOS" bundle exec fastlane test_iOS15_2

## [Tests] Run tests on tvOS 14.3 using sandbox environment
test_tvOS:
ABLY_ENV="sandbox" NAME="ably-tvOS" bundle exec fastlane test_tvOS14_3
ABLY_ENV="sandbox" NAME="ably-tvOS" bundle exec fastlane test_tvOS15_2

## [Tests] Run tests on macOS using sandbox environment
test_macOS:
Expand Down
22 changes: 7 additions & 15 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -1519,16 +1519,8 @@ - (void)realtimeTransportFailed:(id<ARTRealtimeTransport>)transport withError:(A
}
}

switch (transportError.type) {
case ARTRealtimeTransportErrorTypeBadResponse:
case ARTRealtimeTransportErrorTypeOther:
[self transition:ARTRealtimeFailed withErrorInfo:[ARTErrorInfo createFromNSError:transportError.error]];
break;
default: {
ARTErrorInfo *error = [ARTErrorInfo createFromNSError:transportError.error];
[self transitionToDisconnectedOrSuspendedWithError:error];
}
}
ARTErrorInfo *error = [ARTErrorInfo createFromNSError:transportError.error];
[self transitionToDisconnectedOrSuspendedWithError:error];
}

- (void)realtimeTransportNeverConnected:(id<ARTRealtimeTransport>)transport {
Expand All @@ -1537,7 +1529,7 @@ - (void)realtimeTransportNeverConnected:(id<ARTRealtimeTransport>)transport {
return;
}

[self transition:ARTRealtimeFailed withErrorInfo:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport never connected"]];
[self transitionToDisconnectedOrSuspendedWithError:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport never connected"]];
}

- (void)realtimeTransportRefused:(id<ARTRealtimeTransport>)transport withError:(ARTRealtimeTransportError *)error {
Expand All @@ -1547,13 +1539,13 @@ - (void)realtimeTransportRefused:(id<ARTRealtimeTransport>)transport withError:(
}

if (error && error.type == ARTRealtimeTransportErrorTypeRefused) {
[self transition:ARTRealtimeFailed withErrorInfo:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:[NSString stringWithFormat:@"Connection refused using %@", error.url]]];
[self transitionToDisconnectedOrSuspendedWithError:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:[NSString stringWithFormat:@"Connection refused using %@", error.url]]];
}
else if (error) {
[self transition:ARTRealtimeFailed withErrorInfo:[ARTErrorInfo createFromNSError:error.error]];
[self transitionToDisconnectedOrSuspendedWithError:[ARTErrorInfo createFromNSError:error.error]];
}
else {
[self transition:ARTRealtimeFailed];
[self transitionToDisconnectedOrSuspendedWithError:nil];
}
}

Expand All @@ -1563,7 +1555,7 @@ - (void)realtimeTransportTooBig:(id<ARTRealtimeTransport>)transport {
return;
}

[self transition:ARTRealtimeFailed withErrorInfo:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport too big"]];
[self transitionToDisconnectedOrSuspendedWithError:[ARTErrorInfo createWithCode:ARTClientCodeErrorTransport message:@"Transport too big"]];
}

- (void)realtimeTransportSetMsgSerial:(id<ARTRealtimeTransport>)transport msgSerial:(int64_t)msgSerial {
Expand Down
75 changes: 75 additions & 0 deletions Spec/Test Utilities/DataGatherer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Foundation
import XCTest

/**
A `DataGatherer` instance initiates a user-specified data-gathering activity, and provides a method for waiting until the activity submits some data.

The `DataGatherer` instance only cares about the _first_ data that is submitted to it, and will ignore any subsequently-submitted data. When the gathered data has value semantics, this can simplify the implementation of tests, since they do not need to be so careful about making sure to stop their data-gathering process at the right time.
*/
class DataGatherer<T> {
private let expectation: XCTestExpectation

// The value that the initializer’s `gather` block passed to its `submit` argument.
private var value: T?
// Synchronises access to `value`.
private let semaphore = DispatchSemaphore(value: 1)

/**
Initiates the data-gathering process specified by `gather`.

- Parameters:
- description: A human-readable description of the data-gathering process.
- gather: A function which implements the data-gathering process. It should call the `submit` callback with the gathered data when ready. Subsequent calls to `submit` will have no effect. `submit` can be safely called from any thread.
*/
init(description: String, gather: (_ submit: @escaping (T) -> Void) -> Void) {
expectation = XCTestExpectation(description: description)
gather(complete(withValue:))
}

enum Error: Swift.Error {
case unexpectedResult(XCTWaiter.Result)
}

/**
Waits for the initializer’s `gather` function to submit data and then returns the submitted data. If data has already been submitted then it is returned immediately. This method can be safely called from any thread.
*/
func waitForData(timeout: TimeInterval) throws -> T {
semaphore.wait()
if let value = value {
semaphore.signal()
return value
}
semaphore.signal()

let waiter = XCTWaiter()
let result = waiter.wait(for: [expectation], timeout: timeout)

switch result {
case .completed:
let value: T
semaphore.wait()
value = self.value!
semaphore.signal()
return value
default:
throw Error.unexpectedResult(result)
}
}

/**
Waits for the initializer’s `gather` function to submit data and then returns the submitted data. If data has already been submitted then it is returned immediately. This method can be safely called from any thread.
*/
func waitForData(timeout: DispatchTimeInterval) throws -> T {
return try waitForData(timeout: timeout.toTimeInterval())
}

private func complete(withValue value: T) {
semaphore.wait()
if self.value == nil {
self.value = value
}
semaphore.signal()

expectation.fulfill()
}
}
Loading
Loading