-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
@@ -590,12 +590,11 @@ class AuthBackendRPCImplementationTests: RPCBaseTests { | |||
try self.rpcIssuer.respond(withJSON: [:]) | |||
} | |||
_ = try? await rpcImplementation.call(with: request) | |||
// Make sure completeRequest updates. | |||
usleep(10000) |
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.
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>! |
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.
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.
completeRequest = Task { | ||
await AuthBackend.request(withURL: requestURL!, |
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.
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.
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.
LGTM! It's nice to see the usleep
s go away.
Great cleanup. Thanks! |
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