dataconnect(test): add tests for auth token changes concurrent with reconnects#8305
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 reverts commit 48de7f7.
This reverts commit d604197.
This reverts commit 851639d.
…SubscriptionImplUnitTest.kt: `auth token change mid-stream sends update`" This reverts commit 6e4ec5d.
… locally [no ci]" This reverts commit 43e505d.
…e messages to help root cause bugs
…ken update mid-stream
This PR fixes a bug in data connect where Firebase Auth UID changes concurrent with a connection retry could be ignored, and adds unit tests to verify auth token updates and UID changes during reconnection. It also refactors and improves test utilities to enhance test stability and debuggability.
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.onRetryForTestingcallback logic, added test hooks to simulate pending auth tokens during reconnection, and improvedTurbinetesting utilities to include skipped items in failure messages for better debugging.Changelog
View Changelog
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.GetTokenResultinstances underauthTokenResultForhelpers.getAccessTokenImpland leverage the new helpers.TokenUidPairto a top-level declaration.awaitUntilItemandawaitErrorto catch exceptions thrown by Turbine (such as timeouts) and rethrow them with details of skipped items that did not satisfy the predicate.descriptionparameter toawaitUntilItemIsInstanceto improve error messages.descriptionandonIgnoredItemparameters to turbine helper methods (awaitUntilStreamRequest,awaitUntilSubscribeStreamRequest,awaitResponseSender,awaitConnectRpcStarted) to propagate debug info.