Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 459a477

Browse files
authored
test: fail if the same token is seen twice (#983)
The backup pagination test should fail if the same page token is returned twice by the backend, instead of fetching the same page indefinitely. Further investigation is necessary if that actually happens, as it is not something that is expected.
1 parent fc305b7 commit 459a477

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBackupTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@
6363
import java.util.ArrayList;
6464
import java.util.Arrays;
6565
import java.util.Collections;
66+
import java.util.HashSet;
6667
import java.util.List;
67-
import java.util.Random;
68+
import java.util.Set;
6869
import java.util.concurrent.ExecutionException;
6970
import java.util.concurrent.TimeUnit;
7071
import java.util.concurrent.TimeoutException;
@@ -100,7 +101,6 @@ public class ITBackupTest {
100101
private RemoteSpannerHelper testHelper;
101102
private List<String> databases = new ArrayList<>();
102103
private List<String> backups = new ArrayList<>();
103-
private final Random random = new Random();
104104
private String projectId;
105105
private String instanceId;
106106

@@ -580,8 +580,15 @@ private void testPagination(int expectedMinimumTotalBackups) {
580580
assertThat(page.getValues()).hasSize(1);
581581
numBackups++;
582582
assertThat(page.hasNextPage()).isTrue();
583+
Set<String> seenPageTokens = new HashSet<>();
584+
seenPageTokens.add("");
583585
while (page.hasNextPage()) {
584-
logger.info(String.format("Fetching page %d", numBackups + 1));
586+
logger.info(
587+
String.format(
588+
"Fetching page %d with page token %s", numBackups + 1, page.getNextPageToken()));
589+
// The backend should not return the same page token twice.
590+
assertThat(seenPageTokens).doesNotContain(page.getNextPageToken());
591+
seenPageTokens.add(page.getNextPageToken());
585592
page =
586593
dbAdminClient.listBackups(
587594
instanceId, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));

0 commit comments

Comments
 (0)