Skip to content

test(spanner): unflake EndpointLifecycleManagerTest - #15055

Merged
sakthivelmanii merged 2 commits into
mainfrom
unflake-endpointlifecyclemanagertest
Nov 18, 2026
Merged

sakthivelmanii merged 2 commits into
mainfrom
unflake-endpointlifecyclemanagertest

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  • EndpointLifecycleManager.updateActiveAddresses schedules background endpoint creation (createAndStartProbing), which populates endpointCache before calling startProbing to schedule periodic probe execution with initialDelay = 0.
  • EndpointLifecycleManagerTest#transientFailureOscillationWithConnectingStillEvictsEndpoint and EndpointLifecycleManagerTest#readyResetsTransientFailureCounterAfterRecovery only waited for cache.getIfPresent("server1") != null before mutating the fake channel state to TRANSIENT_FAILURE and calling manager.probe("server1") directly on the test thread.
  • Because cache.getIfPresent("server1") != null becomes true before the zero-delay initial background probe("server1") runs, the scheduled probe can observe TRANSIENT_FAILURE concurrently with the manual probe call and increment consecutiveTransientFailures twice (AssertionError: expected:<1> but was:<2>).

Solution

  • Add a @VisibleForTesting enableBackgroundProbing flag on EndpointLifecycleManager (defaulting to true in existing constructors) that skips scheduling periodic probe tasks in startProbing when false.
  • Construct EndpointLifecycleManager with enableBackgroundProbing = false in transientFailureOscillationWithConnectingStillEvictsEndpoint and readyResetsTransientFailureCounterAfterRecovery so background endpoint creation still runs via registerAddresses while all probe("server1") state transitions are driven deterministically on the test thread.

Wait for the initial zero-delay background probe to read CONNECTING state before mutating channel health and driving manual probe calls in EndpointLifecycleManagerTest.
@sakthivelmanii
sakthivelmanii requested review from a team as code owners November 17, 2026 16:18
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) November 17, 2026 16:18
@sakthivelmanii

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 introduces a helper method registerAndAwaitInitialConnectingProbe in EndpointLifecycleManagerTest.java to register an address and wait for the background prober's initial run to read its state. It also updates KeyRangeCacheTest.java to track the number of times getState is called on FakeManagedChannel using an AtomicInteger. These changes help avoid race conditions in tests by ensuring the background prober has completed its initial check before proceeding. I have no feedback to provide as there are no review comments.

@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 introduces test synchronization improvements in EndpointLifecycleManagerTest and KeyRangeCacheTest. Specifically, it adds a helper method registerAndAwaitInitialConnectingProbe to register an endpoint and wait until the background prober's initial run has read its state. To support this, FakeManagedChannel now tracks the number of times its getState method is called using an AtomicInteger. There are no review comments, and I have no feedback to provide.

@sakthivelmanii

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 introduces a new configuration option, enableBackgroundProbing, to the EndpointLifecycleManager class, allowing background probing to be disabled during testing. A new package-private constructor annotated with @VisibleForTesting has been added to support this flag, and existing tests have been updated to disable background probing. There are no review comments, and the changes look clean and well-structured.

@sakthivelmanii
sakthivelmanii merged commit bb8c198 into main Nov 18, 2026
225 of 226 checks passed
@sakthivelmanii
sakthivelmanii deleted the unflake-endpointlifecyclemanagertest branch November 18, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants