Skip to content

Commit 2b4c570

Browse files
authored
fix: only run test if restore succeeded (GoogleCloudPlatform#3553)
The database restore operation could be given up by the test if it fails too many times with an error indicating that too many restore operations are running. The test for listing database operations would still be executed and would then look for the optimize operation of the previous restore. This operation would not be found, as the restore operation was skipped. Fixes GoogleCloudPlatform#3541
1 parent d9dbab4 commit 2b4c570

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

spanner/cloud-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ limitations under the License.
4242
<dependency>
4343
<groupId>com.google.cloud</groupId>
4444
<artifactId>libraries-bom</artifactId>
45-
<version>8.1.0</version>
45+
<version>9.0.0</version>
4646
<type>pom</type>
4747
<scope>import</scope>
4848
</dependency>

spanner/cloud-client/src/test/java/com/example/spanner/SpannerSampleIT.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public void testSample() throws Exception {
296296
// Try the restore operation in a retry loop, as there is a limit on the number of restore
297297
// operations that is allowed to execute simultaneously, and we should retry if we hit this
298298
// limit.
299+
boolean restored = false;
299300
int restoreAttempts = 0;
300301
while (true) {
301302
try {
@@ -306,6 +307,7 @@ public void testSample() throws Exception {
306307
+ "] from ["
307308
+ backupId.getName()
308309
+ "]");
310+
restored = true;
309311
break;
310312
} catch (SpannerException e) {
311313
if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION
@@ -325,14 +327,16 @@ public void testSample() throws Exception {
325327
}
326328
}
327329

328-
out = runSample("listdatabaseoperations");
329-
assertThat(out).contains(
330-
String.format(
331-
"Database %s restored from backup",
332-
DatabaseId.of(
333-
dbId.getInstanceId(),
334-
SpannerSample.createRestoredSampleDbId(dbId))
335-
.getName()));
330+
if (restored) {
331+
out = runSample("listdatabaseoperations");
332+
assertThat(out).contains(
333+
String.format(
334+
"Database %s restored from backup",
335+
DatabaseId.of(
336+
dbId.getInstanceId(),
337+
SpannerSample.createRestoredSampleDbId(dbId))
338+
.getName()));
339+
}
336340

337341
out = runSample("updatebackup");
338342
assertThat(out).contains(

0 commit comments

Comments
 (0)