Skip to content

Commit 15467c8

Browse files
test(spanner): make sequence sample integration tests resilient to retries (googleapis#13183)
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.
1 parent fe608fe commit 15467c8

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

java-spanner/samples/snippets/src/test/java/com/example/spanner/SequenceSampleIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public void createSequence() throws Exception {
9393
out.contains(
9494
"Created Seq sequence and Customers table, where the key column "
9595
+ "CustomerId uses the sequence as a default value"));
96-
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
96+
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
97+
assertTrue(insertCount > 0 && insertCount % 3 == 0);
9798
assertTrue(out.contains("Number of customer records inserted is: 3"));
9899
}
99100

@@ -115,7 +116,8 @@ public void alterSequence() throws Exception {
115116
}
116117
assertTrue(
117118
out.contains("Altered Seq sequence to skip an inclusive range between 1000 and 5000000"));
118-
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
119+
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
120+
assertTrue(insertCount > 0 && insertCount % 3 == 0);
119121
assertTrue(out.contains("Number of customer records inserted is: 3"));
120122
}
121123

java-spanner/samples/snippets/src/test/java/com/example/spanner/admin/archived/SequenceSampleIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public void createSequence() throws Exception {
9696
out.contains(
9797
"Created Seq sequence and Customers table, where its key column "
9898
+ "CustomerId uses the sequence as a default value"));
99-
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
99+
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
100+
assertTrue(insertCount > 0 && insertCount % 3 == 0);
100101
assertTrue(out.contains("Number of customer records inserted is: 3"));
101102
}
102103

@@ -118,7 +119,8 @@ public void alterSequence() throws Exception {
118119
}
119120
assertTrue(
120121
out.contains("Altered Seq sequence to skip an inclusive range between 1000 and 5000000"));
121-
assertEquals(out.split("Inserted customer record with CustomerId", -1).length - 1, 3);
122+
int insertCount = out.split("Inserted customer record with CustomerId", -1).length - 1;
123+
assertTrue(insertCount > 0 && insertCount % 3 == 0);
122124
assertTrue(out.contains("Number of customer records inserted is: 3"));
123125
}
124126

0 commit comments

Comments
 (0)