-
Notifications
You must be signed in to change notification settings - Fork 200
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
implements new Storage API for handleEventsForBackgroundURLSession #2481
base: main
Are you sure you want to change the base?
Conversation
@@ -7,30 +7,44 @@ | |||
|
|||
import Foundation | |||
|
|||
extension Notification.Name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This notification was setup just for unit test? Looks like this will be fired in the production app as well. We should think about a better way to make this class testable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other options do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test worked without the notification expectation:
func testRegisteringAndUnregister() async throws {
let identifier = UUID().uuidString
let otherIdentifier = UUID().uuidString
await StorageBackgroundEventsRegistry.shared.register(identifier: identifier)
let done = asyncExpectation(description: "done")
Task {
let handled = await StorageBackgroundEventsRegistry.shared.handleEventsForBackgroundURLSession(identifier: identifier)
await done.fulfill()
XCTAssertTrue(handled)
}
let didContinue = await handleEvents(for: identifier)
XCTAssertTrue(didContinue)
await waitForExpectations([done])
let otherDone = asyncExpectation(description: "other done")
Task {
let otherHandled = await StorageBackgroundEventsRegistry.shared.handleEventsForBackgroundURLSession(identifier: otherIdentifier)
await otherDone.fulfill()
XCTAssertFalse(otherHandled)
}
let didNotContinue = await handleEvents(for: otherIdentifier)
XCTAssertFalse(didNotContinue)
await waitForExpectations([otherDone])
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to run it on macOS many times repeatedly to get it to fail. Without the notification it is a flaky test which will fail based on timing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This issue can then happen in the real app as well right? What if the URLSession call back reach before we setup the continuation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option could be to create an overloaded function just for test:
func handleEventsForBackgroundURLSession(identifier: String) async -> Bool {
return await handleEventsForBackgroundURLSession(identifier: identifier, notifyTest: nil)
}
func handleEventsForBackgroundURLSession(identifier: String, notifyTest: ((String) -> Void)? ) async -> Bool {
guard self.identifier == identifier else { return false }
return await withCheckedContinuation { (continuation: CheckedContinuation<Bool, Never>) in
self.continuation = continuation
if let notifyTest = notifyTest {
notifyTest(identifier)
}
}
}
...ns/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageBackgroundEventsRegistry.swift
Show resolved
Hide resolved
…ationCenter is defined
0a1c1ef
to
175dc7d
Compare
When can we expect this to be released? |
Issue #, if available:
N/A
Description of changes:
Check points: (check or cross out if not relevant)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.