Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void createSpannerInstance() {
public void testCreateSessionDeadlineExceeded() {
// Simulate a problem with the CreateSession RPC making it slow.
mockSpanner.setCreateSessionExecutionTime(
SimulatedExecutionTime.ofException(Status.DEADLINE_EXCEEDED.asRuntimeException()));
SimulatedExecutionTime.ofStickyException(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.

high

Using ofStickyException ensures that the exception persists across multiple calls, which is necessary to fix the flakiness caused by background tasks. However, because sticky exceptions do not clear themselves after being triggered, it is critical to ensure that mockSpanner.removeAllExecutionTimes() is called in a finally block or a teardown method (e.g., @After) to prevent this failure from leaking into subsequent tests that share the same mock server instance.

References
  1. The implementation must be exception-safe to prevent resource leaks or state contamination, meaning all opened resources or mock states should be closed or cleared even if exceptions occur.

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.

We are already calling mockSpanner.removeAllExecutionTimes() below which should be suffice.


Spanner testSpanner =
SpannerOptions.newBuilder()
Expand Down
Loading