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

[Infra] Reduce test flakes due to async variable assignment #13610

Merged
merged 3 commits into from
Sep 9, 2024

Conversation

ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Sep 9, 2024

This pattern should hopefully reduce testing flakes such as this: https://github.com/firebase/firebase-ios-sdk/actions/runs/10770066986/job/29862664996

Comments throughout to document approach.

#no-changelog

@@ -590,12 +590,11 @@ class AuthBackendRPCImplementationTests: RPCBaseTests {
try self.rpcIssuer.respond(withJSON: [:])
}
_ = try? await rpcImplementation.call(with: request)
// Make sure completeRequest updates.
usleep(10000)
Copy link
Member Author

@ncooke3 ncooke3 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this leads to flakes on slower CI machines where this is not a long enough wait.

@@ -52,7 +52,7 @@ class FakeBackendRPCIssuer: NSObject, AuthBackendRPCIssuer {
/** @property completeRequest
@brief The last request to be processed by the backend.
*/
var completeRequest: URLRequest?
var completeRequest: Task<URLRequest, Never>!
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the tests, it wouldn't make sense to access this property before doing _ = try? await rpcImplementation.call(with: request), so this is implicitly unwrapped.

Comment on lines +151 to +152
completeRequest = Task {
await AuthBackend.request(withURL: requestURL!,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, assigning this property in the task led to it being resolved later than the method returns, causing for the need to sleep since it was assigned as a side effect of the _ = try? await rpcImplementation.call(with: request) call. Now, the task is synchronously assigned to it's resolved value can be async-ly waited on later.

Copy link
Contributor

@andrewheard andrewheard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! It's nice to see the usleeps go away.

@ncooke3 ncooke3 merged commit b2a33ce into main Sep 9, 2024
56 checks passed
@ncooke3 ncooke3 deleted the nc/less-flaky-test branch September 9, 2024 21:40
@ncooke3 ncooke3 mentioned this pull request Sep 9, 2024
@paulb777
Copy link
Member

Great cleanup. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants