Skip to content

fix(spanner): fix flakiness and race conditions in multiplexed session tests#12949

Merged
sakthivelmanii merged 1 commit intomainfrom
fix-multiplexed-session-test
Apr 29, 2026
Merged

fix(spanner): fix flakiness and race conditions in multiplexed session tests#12949
sakthivelmanii merged 1 commit intomainfrom
fix-multiplexed-session-test

Conversation

@sakthivelmanii
Copy link
Copy Markdown
Contributor

@sakthivelmanii sakthivelmanii commented Apr 29, 2026

No description provided.

@sakthivelmanii sakthivelmanii requested review from a team as code owners April 29, 2026 10:14
Copy link
Copy Markdown
Contributor

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

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 helper method, ofMinimumAndRandomTimeAndStickyException, in MockSpannerServiceImpl to simulate RPC delays alongside persistent exceptions. Corresponding tests in MultiplexedSessionDatabaseClientMockServerTest were updated to utilize this method. Feedback suggests replacing the magic number 200 with a named constant for better clarity and considering a more targeted reset of execution times instead of using the broad removeAllExecutionTimes() method.

mockSpanner.setCreateSessionExecutionTime(
SimulatedExecutionTime.ofStickyException(Status.DEADLINE_EXCEEDED.asRuntimeException()));
SimulatedExecutionTime.ofMinimumAndRandomTimeAndStickyException(
200, 0, Status.DEADLINE_EXCEEDED.asRuntimeException()));
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

The magic number 200 is used here and in other places (e.g., line 342) to represent the simulated execution delay. It would be better to define this as a named constant (e.g., SIMULATED_RPC_DELAY_MS) to improve maintainability and clarity across the test suite.

// The CreateSession RPC will be retried, and as the exception is removed by the first call,
// The CreateSession RPC will be retried, and as we manually clear the exception,
// the second attempt will succeed.
mockSpanner.removeAllExecutionTimes();
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

The use of removeAllExecutionTimes() is quite broad as it clears all simulated execution times for all RPC methods. While safe in this specific test context, consider using a more targeted reset (e.g., setCreateSessionExecutionTime(null)) if available, to avoid unintended side effects in more complex test scenarios where other RPCs might have configured behaviors.

@sakthivelmanii sakthivelmanii force-pushed the fix-multiplexed-session-test branch 2 times, most recently from e55d353 to 15b11ed Compare April 29, 2026 11:59
}

private void maybeFreezeAndRecordRequest(AbstractMessage request) {
synchronized (lock) {
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.

(Probably does not matter much, but still): Do you really need to take the lock here?

@sakthivelmanii sakthivelmanii force-pushed the fix-multiplexed-session-test branch from 15b11ed to acc5b8c Compare April 29, 2026 14:09
@sakthivelmanii sakthivelmanii merged commit 3e02f18 into main Apr 29, 2026
130 of 131 checks passed
@sakthivelmanii sakthivelmanii deleted the fix-multiplexed-session-test branch April 29, 2026 16:19
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.

3 participants