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

chore: kickoff release #3555

Merged
merged 6 commits into from
Mar 7, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/integ_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration Tests
name: Integration Tests (Except DataStore & API)
on:
workflow_dispatch:
push:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/issue_closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
message: |
### ⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
3 changes: 1 addition & 2 deletions .github/workflows/nightly_repeated_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ jobs:
scheme: ${{ matrix.scheme }}
timeout-minutes: 50
generate_coverage_report: false
retry_on_error: false
other_flags: -test-iterations 100 -run-tests-until-failure
test_iterations_flags: -test-iterations 100 -run-tests-until-failure
9 changes: 7 additions & 2 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ on:
required: false
type: boolean
default: false
test_iterations_flags:
description: 'The xcodebuild flags used when running the test. Defaults to retrying on failure up to 3 times'
required: false
type: string
default: '-test-iterations 3 -retry-tests-on-failure'

permissions:
contents: read
Expand Down Expand Up @@ -82,7 +87,7 @@ jobs:
cloned_source_packages_path: ~/Library/Developer/Xcode/DerivedData/Amplify
derived_data_path: ${{ github.workspace }}/Build
disable_package_resolution: ${{ steps.dependencies-cache.outputs.cache-hit }}
other_flags: -test-iterations 3 -retry-tests-on-failure
other_flags: ${{ inputs.test_iterations_flags }}

- name: Retry ${{ inputs.platform }} Unit Tests
if: steps.run-tests.outcome=='failure'
Expand All @@ -98,7 +103,7 @@ jobs:
cloned_source_packages_path: ~/Library/Developer/Xcode/DerivedData/Amplify
derived_data_path: ${{ github.workspace }}/Build
disable_package_resolution: true
other_flags: -test-iterations 3 -retry-tests-on-failure
other_flags: ${{ inputs.test_iterations_flags }}

- name: Store Coverage Report File
if: ${{ inputs.generate_coverage_report == true }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/run_unit_tests_platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ on:
required: false
type: boolean
default: false
test_iterations_flags:
description: 'The xcodebuild flags used when running the test. Defaults to retrying on failure up to 3 times'
required: false
type: string
default: '-test-iterations 3 -retry-tests-on-failure'

permissions:
contents: read
Expand All @@ -37,4 +42,5 @@ jobs:
scheme: ${{ inputs.scheme }}
platform: ${{ matrix.platform }}
generate_coverage_report: ${{ github.event_name != 'workflow_dispatch' && matrix.platform == 'iOS' && inputs.generate_coverage_report }}
timeout-minutes: ${{ inputs.timeout-minutes }}
timeout-minutes: ${{ inputs.timeout-minutes }}
test_iterations_flags: ${{ inputs.test_iterations_flags }}
4 changes: 3 additions & 1 deletion Amplify/Resources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<array/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDataTypes</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3554,7 +3554,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mattgallagher/CwlPreconditionTesting.git";
requirement = {
kind = upToNextMinorVersion;
kind = upToNextMajorVersion;
minimumVersion = 2.1.0;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDataTypes</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
</dict>
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array>
<dict>
<key>NSPrivacyCollectedDataType</key>
<string>NSPrivacyCollectedDataTypeOtherDataTypes</string>
<key>NSPrivacyCollectedDataTypeLinked</key>
<false/>
<key>NSPrivacyCollectedDataTypeTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypePurposes</key>
<array>
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
</array>
</dict>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public protocol AuthorizationTypeIterator {

/// Total number of values
var count: Int { get }

/// Whether iterator has next available `AuthorizationType` to return or not
var hasNext: Bool { get }

/// Next available `AuthorizationType` or `nil` if exhausted
mutating func next() -> AuthorizationType?
Expand All @@ -66,18 +69,29 @@ public struct AWSAuthorizationTypeIterator: AuthorizationTypeIterator {

private var values: IndexingIterator<[AWSAuthorizationType]>
private var _count: Int
private var _position: Int

public init(withValues values: [AWSAuthorizationType]) {
self.values = values.makeIterator()
self._count = values.count
self._position = 0
}

public var count: Int {
_count
}

public var hasNext: Bool {
_position < _count
}

public mutating func next() -> AWSAuthorizationType? {
values.next()
if let value = values.next() {
_position += 1
return value
}

return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation {

/// - Warning: Must be invoked from a locking context
private func shouldRetryWithDifferentAuthType() -> RequestRetryAdvice {
let shouldRetry = (authTypesIterator?.count ?? 0) > 0
let shouldRetry = authTypesIterator?.hasNext == true
return RequestRetryAdvice(shouldRetry: shouldRetry, retryInterval: .milliseconds(0))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,68 @@ class SyncMutationToCloudOperationTests: XCTestCase {
XCTAssertTrue(advice.shouldRetry)
}

/// Given: Model with multiple auth types. Mutation requests always fail with 401 error code
/// When: Mutating model fails with 401
/// Then: DataStore will try again with each auth type and eventually fails
func testGetRetryAdviceForEachModelAuthTypeThenFail_HTTPStatusError401() async throws {
var numberOfTimesEntered = 0
let mutationEvent = try createMutationEvent()
let authStrategy = MockMultiAuthModeStrategy()
let expectedNumberOfTimesEntered = authStrategy.authTypesFor(schema: mutationEvent.schema, operation: .create).count

let expectCalllToApiMutateNTimesAndFail = expectation(description: "Call API.mutate \(expectedNumberOfTimesEntered) times and then fail")

let response = HTTPURLResponse(url: URL(string: "http://localhost")!,
statusCode: 401,
httpVersion: nil,
headerFields: nil)!
let error = APIError.httpStatusError(401, response)

let operation = await SyncMutationToCloudOperation(
mutationEvent: mutationEvent,
getLatestSyncMetadata: { nil },
api: mockAPIPlugin,
authModeStrategy: authStrategy,
networkReachabilityPublisher: publisher,
currentAttemptNumber: 1,
completion: { result in
if numberOfTimesEntered == expectedNumberOfTimesEntered {
expectCalllToApiMutateNTimesAndFail.fulfill()

} else {
XCTFail("API.mutate was called incorrect amount of times, expected: \(expectedNumberOfTimesEntered), was : \(numberOfTimesEntered)")
}
}
)

let responder = MutateRequestListenerResponder<MutationSync<AnyModel>> { request, eventListener in
let requestOptions = GraphQLOperationRequest<MutationSync<AnyModel>>.Options(pluginOptions: nil)
let request = GraphQLOperationRequest<MutationSync<AnyModel>>(apiName: request.apiName,
operationType: .mutation,
document: request.document,
variables: request.variables,
responseType: request.responseType,
options: requestOptions)
let operation = MockGraphQLOperation(request: request, responseType: request.responseType)

numberOfTimesEntered += 1

DispatchQueue.global().sync {
// Fail with 401 status code
eventListener!(.failure(error))
}

return operation
}

mockAPIPlugin.responders[.mutateRequestListener] = responder

let queue = OperationQueue()
queue.addOperation(operation)

await fulfillment(of: [expectCalllToApiMutateNTimesAndFail], timeout: defaultAsyncWaitTimeout)
}

func testGetRetryAdvice_OperationErrorAuthErrorWithMultiAuth_RetryTrue() async throws {
let operation = await SyncMutationToCloudOperation(
mutationEvent: try createMutationEvent(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSPluginsCore

class AWSAuthorizationTypeIteratorTests: XCTestCase {

func testEmptyIterator_hasNextValue_false() throws {
var iterator = AWSAuthorizationTypeIterator(withValues: [])

XCTAssertFalse(iterator.hasNext)
XCTAssertNil(iterator.next())
}

func testOneElementIterator_hasNextValue_once() throws {
var iterator = AWSAuthorizationTypeIterator(withValues: [.amazonCognitoUserPools])

XCTAssertTrue(iterator.hasNext)
XCTAssertNotNil(iterator.next())

XCTAssertFalse(iterator.hasNext)
}

func testTwoElementsIterator_hasNextValue_twice() throws {
var iterator = AWSAuthorizationTypeIterator(withValues: [.amazonCognitoUserPools, .apiKey])

XCTAssertTrue(iterator.hasNext)
XCTAssertNotNil(iterator.next())

XCTAssertTrue(iterator.hasNext)
XCTAssertNotNil(iterator.next())

XCTAssertFalse(iterator.hasNext)
}
}
Loading
Loading