Skip to content

Commit 96fa0ee

Browse files
sakthivelmaniilqiu96
authored andcommitted
test(spanner): unflake DynamicChannelPoolPrimeSessionTest (#14278)
In `sessionArrivingAfterFailedClientConstructionNeverBecomesPrimeSession`, `arrivedBeforeRelease` was sampled immediately after `getDatabaseClient` timed out from waiting for multiplexed session creation (200ms). Under thread scheduling contention or high CI load, the asynchronous `CreateSession` gRPC call dispatched by `SessionClient` could take longer than 200ms to reach the mock server. As a result, `arrivedBeforeRelease` sampled 0 instead of 1. When the gate was later released, the delayed RPC finally arrived at `mockSpanner.createSession()`, incrementing the count and causing `assertEquals(arrivedBeforeRelease, mockSpanner.arrivedCreateSessions.get())` to fail with `AssertionError: expected:<0> but was:<1>`. Fix this race condition by explicitly waiting for the in-flight `CreateSession` RPC to arrive at `mockSpanner` before sampling `arrivedBeforeRelease` and releasing the gate.
1 parent 783b6ac commit 96fa0ee

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DynamicChannelPoolPrimeSessionTest.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ public void sessionArrivingAfterFailedClientConstructionNeverBecomesPrimeSession
379379
// arrives.
380380
assertThat(waitingRpc.getPrimeSessionSourceCount()).isEqualTo(0);
381381

382+
awaitCondition(() -> mockSpanner.arrivedCreateSessions.get() >= 1);
382383
int arrivedBeforeRelease = mockSpanner.arrivedCreateSessions.get();
383384
mockSpanner.releaseCreateSessions();
384385
awaitCondition(() -> waitingRpc.getCompletedMultiplexedCreateSessions() >= 1);

0 commit comments

Comments
 (0)