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

fix: skip network monitoring for watchOS #3272

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add some unit tests for DS
  • Loading branch information
lawmicha committed Nov 9, 2023
commit 68b3135182b1854d32452af148789a4e308f711a
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,42 @@ class AWSIncomingEventReconciliationQueueTests: XCTestCase {
sink.cancel()

}

// This test case tests that initialized event is received even
// all models fail with a "OperationNotAllowed"
func testSubscriptionFailedBecauseOfOperationNotAllowed() async {
let expectStarted = expectation(description: "eventQueue expected to send out started state")
let expectInitialized = expectation(description: "eventQueue expected to send out initialized state")
let eventQueue = await initEventQueue(modelSchemas: [Post.schema])
eventQueue.start()

let sink = eventQueue.publisher.sink(receiveCompletion: { _ in
XCTFail("Not expecting this to call")
}, receiveValue: { event in
switch event {
case .idle:
break
case .started:
expectStarted.fulfill()
case .initialized:
expectInitialized.fulfill()
default:
XCTFail("Should not expect any other state, received: \(event)")
}
})

let reconciliationQueues = MockModelReconciliationQueue.mockModelReconciliationQueues
for (queueName, queue) in reconciliationQueues {
let cancellableOperation = CancelAwareBlockOperation {
let event: ModelReconciliationQueueEvent = .disconnected(modelName: queueName, reason: .operationNotAllowed)
queue.modelReconciliationQueueSubject.send(event)
}
operationQueue.addOperation(cancellableOperation)
}
operationQueue.isSuspended = false
await waitForExpectations(timeout: 2)

sink.cancel()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ extension ModelReconciliationQueueBehaviorTests {
let dataStoreError = DataStoreError.api(apiError, nil)
return .failure(dataStoreError)
}

private func completionSignalWithOperationWatchOSRelatedError() -> Subscribers.Completion<DataStoreError> {
let apiError = APIError.operationError("watchOS related error", "recovery message", nil)
let dataStoreError = DataStoreError.api(apiError, nil)
return .failure(dataStoreError)
}

func testProcessingUnauthorizedError() async {
let eventSentViaPublisher = expectation(description: "Sent via publisher")
Expand All @@ -429,10 +435,11 @@ extension ModelReconciliationQueueBehaviorTests {
XCTFail("Not expecting a call to completion, received \(value)")
}, receiveValue: { event in
switch event {
case .idle:
break
default:
case .disconnected(_, let reason):
XCTAssertEqual(reason, .unauthorized)
eventSentViaPublisher.fulfill()
default:
break
}
})

Expand All @@ -457,10 +464,40 @@ extension ModelReconciliationQueueBehaviorTests {
XCTFail("Not expecting a call to completion, received \(value)")
}, receiveValue: { event in
switch event {
case .idle:
break
case .disconnected(_, let reason):
XCTAssertEqual(reason, .operationDisabled)
eventSentViaPublisher.fulfill()
default:
break
}
})

subscriptionEventsSubject.send(completion: completion)
wait(for: [eventSentViaPublisher], timeout: 1.0)
queueSink.cancel()
}

func testProcessingOperationNotAllowedError() async {
let eventSentViaPublisher = expectation(description: "Sent via publisher")
let queue = await AWSModelReconciliationQueue(modelSchema: MockSynced.schema,
storageAdapter: storageAdapter,
api: apiPlugin,
reconcileAndSaveQueue: reconcileAndSaveQueue,
modelPredicate: modelPredicate,
auth: authPlugin,
authModeStrategy: AWSDefaultAuthModeStrategy(),
incomingSubscriptionEvents: subscriptionEventsPublisher)
let completion = completionSignalWithOperationWatchOSRelatedError()

let queueSink = queue.publisher.sink(receiveCompletion: { value in
XCTFail("Not expecting a call to completion, received \(value)")
}, receiveValue: { event in
switch event {
case .disconnected(_, let reason):
XCTAssertEqual(reason, .operationNotAllowed)
eventSentViaPublisher.fulfill()
default:
break
}
})

Expand Down
Loading