test(spanner): make sequence sample integration tests resilient to retries#13183
test(spanner): make sequence sample integration tests resilient to retries#13183sakthivelmanii wants to merge 1 commit into
Conversation
…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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| assertTrue(insertCount > 0 && insertCount % 3 == 0); | |
| assertTrue(insertCount >= 3); |
Updates
SequenceSampleITand 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.