dataconnect(test): add tests for auth token changes concurrent with reconnects#8305
dataconnect(test): add tests for auth token changes concurrent with reconnects#8305dconeybe wants to merge 8 commits into
Conversation
…ce it was never actually used
…rrent with reconnect were ignored, but should have resulted in AuthUidChangedException. The root cause was that the sequence number was checked before the auth uid change. Switching the order fixes the bug, because the authuid of the outdated auth token is still relevant.
…ncurrent with reconnects
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
…n and MutableAuthProvider [no ci]
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the auth token handling and reconnection logic in DataConnectBidiConnectStream, ensuring that AuthUidChangedException is prioritized over sequence number checks during reconnections. It also introduces new unit tests to verify auth token updates and concurrent reconnection scenarios. In the test utilities, BaseInternalAuthProvider is refactored to simplify token retrieval. The review feedback suggests consolidating the overloaded authTokenResultFor helper functions in AccessTokenTestUtils.kt into a single, cleaner function to avoid duplication and suppress annotations.
…tEvent() throws an exception
…tionImplUnitTest.kt: `auth token change mid-stream sends update`
This PR adds data connect unit tests verifying the behavior of auth token updates during connection retries, and fixes a bug where Firebase Auth UID changes concurrent with a connection retry could be ignored instead of throwing an
AuthUidChangedException. It also refactors the testing utilities to support testing mutable auth providers.Highlights
ConnectionStateUpdaterwhere an auth UID change concurrent with a stream reconnection attempt could be ignored if its sequence number was stale, ensuring anAuthUidChangedExceptionis always thrown.OnRetryForTestinglogic, added a newMutableAuthProvidertest utility to facilitate testing dynamic auth state changes, and centralized fake token generation.Changelog
Detailed file changes
ConnectionStateUpdaterto avoid ignoring concurrent UID changes.setReconnectPendingAuthTokenForTesting/unsetReconnectPendingAuthTokenForTesting) to simulate pending auth tokens during reconnection.onRetryForTestingcallback logic.flow retries if server connection is lostunit test for better grouping.MutableAuthProviderto mock an auth provider that can change tokens dynamically.GetTokenResultinstances underauthTokenResultForhelpers.getAccessTokenImpland leverage the new helpers.TokenUidPairto a top-level declaration.