Skip to content

dataconnect(test): add tests for auth token changes concurrent with reconnects#8305

Draft
dconeybe wants to merge 8 commits into
mainfrom
dconeybe/dataconnect/RealtimeAuthUid6
Draft

dataconnect(test): add tests for auth token changes concurrent with reconnects#8305
dconeybe wants to merge 8 commits into
mainfrom
dconeybe/dataconnect/RealtimeAuthUid6

Conversation

@dconeybe

@dconeybe dconeybe commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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

  • Auth UID Change Handling: Fixed a bug in ConnectionStateUpdater where an auth UID change concurrent with a stream reconnection attempt could be ignored if its sequence number was stale, ensuring an AuthUidChangedException is always thrown.
  • Concurrent Auth Tests: Added comprehensive unit tests covering various scenarios of auth token changes concurrent with stream reconnection (e.g., when the token is fresh, stale, or has a changed UID).
  • Test Utility Cleanup & Improvements: Removed unused OnRetryForTesting logic, added a new MutableAuthProvider test utility to facilitate testing dynamic auth state changes, and centralized fake token generation.

Changelog

Detailed file changes
  • DataConnectBidiConnectStream.kt:
    • Prioritized checking for auth UID changes before checking sequence numbers or token equality in ConnectionStateUpdater to avoid ignoring concurrent UID changes.
    • Added test hooks (setReconnectPendingAuthTokenForTesting / unsetReconnectPendingAuthTokenForTesting) to simulate pending auth tokens during reconnection.
    • Removed unused onRetryForTesting callback logic.
  • QuerySubscriptionImplUnitTest.kt:
    • Added new test cases verifying auth token updates (both fresh and stale) and auth UID changes occurring concurrently with reconnection.
    • Moved the existing flow retries if server connection is lost unit test for better grouping.
  • AccessTokenTestUtils.kt:
    • Added MutableAuthProvider to mock an auth provider that can change tokens dynamically.
    • Centralized the creation of test GetTokenResult instances under authTokenResultFor helpers.
    • Refactored base and concrete fake auth providers to override getAccessTokenImpl and leverage the new helpers.
    • Moved TokenUidPair to a top-level declaration.

dconeybe added 3 commits June 15, 2026 14:02
…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.
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

📝 PRs merging into main branch

Our 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.

@dconeybe

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant