Skip to content

test(spanner): make sequence sample integration tests resilient to retries#13183

Open
sakthivelmanii wants to merge 1 commit into
mainfrom
fix/spanner-sequence-sample-flakiness
Open

test(spanner): make sequence sample integration tests resilient to retries#13183
sakthivelmanii wants to merge 1 commit into
mainfrom
fix/spanner-sequence-sample-flakiness

Conversation

@sakthivelmanii
Copy link
Copy Markdown
Contributor

Updates SequenceSampleIT and its archived counterpart to verify that the count of per-row console output messages is a positive multiple of 3. This prevents flakiness caused by Cloud Spanner read-write transaction retries while keeping the public sample snippet code pristine and minimal for documentation readers.

…tries

Updates SequenceSampleIT and its archived counterpart to verify that the count of per-row console output messages is a positive multiple of 3. This prevents flakiness caused by Cloud Spanner read-write transaction retries while keeping the public sample snippet code pristine and minimal for documentation readers.
@sakthivelmanii sakthivelmanii requested review from a team as code owners May 13, 2026 07:06
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 updates integration tests for Spanner sequences to mitigate flakiness by replacing exact count assertions with checks for multiples of three. The reviewer pointed out that the modulo-based check remains potentially flaky due to transaction retries and partial executions, suggesting a more resilient assertion that simply verifies the count is at least three.

+ "CustomerId uses the sequence as a default value"));
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
assertTrue(insertCount > 0 && insertCount % 3 == 0);
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 condition insertCount % 3 == 0 may still be flaky if a transaction aborts and retries during the execution of the block (e.g., after some but not all rows are processed). In such cases, partial output from the aborted attempt would result in a total count that is not a multiple of 3. Using insertCount >= 3 is more resilient to such partial executions.

Suggested change
assertTrue(insertCount > 0 && insertCount % 3 == 0);
assertTrue(insertCount >= 3);

out.contains("Altered Seq sequence to skip an inclusive range between 1000 and 5000000"));
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
assertTrue(insertCount > 0 && insertCount % 3 == 0);
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 condition insertCount % 3 == 0 may still be flaky if a transaction aborts and retries during the execution of the block. Using insertCount >= 3 is more resilient to partial executions during retries.

Suggested change
assertTrue(insertCount > 0 && insertCount % 3 == 0);
assertTrue(insertCount >= 3);

+ "CustomerId uses the sequence as a default value"));
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
assertTrue(insertCount > 0 && insertCount % 3 == 0);
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 condition insertCount % 3 == 0 may still be flaky if a transaction aborts and retries during the execution of the block. Using insertCount >= 3 is more resilient to partial executions during retries.

Suggested change
assertTrue(insertCount > 0 && insertCount % 3 == 0);
assertTrue(insertCount >= 3);

out.contains("Altered Seq sequence to skip an inclusive range between 1000 and 5000000"));
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
assertTrue(insertCount > 0 && insertCount % 3 == 0);
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 condition insertCount % 3 == 0 may still be flaky if a transaction aborts and retries during the execution of the block. Using insertCount >= 3 is more resilient to partial executions during retries.

Suggested change
assertTrue(insertCount > 0 && insertCount % 3 == 0);
assertTrue(insertCount >= 3);

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.

1 participant