Skip to content

test(spanner): unflake LocationAwareSharedBackendReplicaHarnessTest - #14396

Merged
sakthivelmanii merged 1 commit into
mainfrom
unflake-location-aware-shared-backend-replica-harness
Sep 16, 2026
Merged

sakthivelmanii merged 1 commit into
mainfrom
unflake-location-aware-shared-backend-replica-harness

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Wait for all backend replicas to establish active transport connections before issuing the warmup query in waitForReplicaRoutedRead.

Previously, waitForReplicaRoutedRead exited as soon as the first replica handled the initial warmup read. In fast test executions, secondary replicas could still be completing their background Netty channel handshakes initiated by EndpointLifecycleManager probing. When the primary replica subsequently failed, secondary replicas were evaluated as unhealthy (channel state not yet READY) and skipped, causing traffic to unexpectedly fall back to defaultReplica.

Tracking active transport connections via ServerTransportFilter in SharedBackendReplicaHarness ensures all replica channels are connected and ready before test assertions begin.

@sakthivelmanii
sakthivelmanii requested review from a team as code owners September 16, 2026 05:58

@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 connection tracking for replicas in SharedBackendReplicaHarness to ensure all replicas are connected before executing tests in LocationAwareSharedBackendReplicaHarnessTest. This is achieved by adding a ServerTransportFilter to the gRPC server and tracking active connections with an AtomicInteger. The review feedback suggests a robust improvement to prevent the activeConnections counter from dropping below zero in recordConnectionTerminated if a transport terminates without a successful handshake, which could otherwise lead to incorrect connection state tracking.

Comment on lines +87 to +89
void recordConnectionTerminated() {
activeConnections.decrementAndGet();
}

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.

medium

Under certain network conditions or connection handshake failures, gRPC's transportTerminated can be invoked without a corresponding successful transportReady call. If this occurs, activeConnections could decrement below zero, causing subsequent successful connections to not be recognized correctly (since activeConnections.get() > 0 would remain false or delayed). To make the connection tracking robust against such anomalies, consider using updateAndGet to prevent the counter from dropping below zero.

Suggested change
void recordConnectionTerminated() {
activeConnections.decrementAndGet();
}
void recordConnectionTerminated() {
activeConnections.updateAndGet(val -> Math.max(0, val - 1));
}

if (harness.allReplicasConnected()) {
return;
}
Thread.sleep(20L);

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.

nit: we could use awaitility here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

await?

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.

Yes org.awaitility.Awaitility.await

Wait for all backend replicas to establish active transport connections
before issuing the warmup query in waitForReplicaRoutedRead.

Previously, waitForReplicaRoutedRead exited as soon as the first replica
handled the initial warmup read. In fast test executions, secondary
replicas could still be completing their background Netty channel
handshakes initiated by EndpointLifecycleManager probing. When the
primary replica subsequently failed, secondary replicas were evaluated
as unhealthy (channel state not yet READY) and skipped, causing traffic
to unexpectedly fall back to defaultReplica.

Tracking active transport connections via ServerTransportFilter in
SharedBackendReplicaHarness ensures all replica channels are connected
and ready before test assertions begin.
@sakthivelmanii
sakthivelmanii force-pushed the unflake-location-aware-shared-backend-replica-harness branch from 0e8b6fc to ba70900 Compare September 16, 2026 07:26
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) September 16, 2026 07:30
@sakthivelmanii
sakthivelmanii merged commit 151e5c0 into main Sep 16, 2026
205 of 206 checks passed
@sakthivelmanii
sakthivelmanii deleted the unflake-location-aware-shared-backend-replica-harness branch September 16, 2026 07:49
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