Skip to content
Permalink
Browse files
fix: always delete all backups from an owned test instance (#557)
* fix: always delete all backups from an owned test instance

An instance can only be deleted once all backups on the instance have been
deleted. The integration test environment should therefore first delete all
backups on an owned instance before trying to delete the instance itself.

Fixes #542

* fix: do not try to list backups on emulator
  • Loading branch information
olavloite committed Oct 27, 2020
1 parent b3c96f2 commit ff571b01b9dffdda44a9bd322e04ff04b5b5c57a
Showing with 15 additions and 0 deletions.
  1. +15 −0 google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java
@@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkState;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
import com.google.cloud.spanner.testing.RemoteSpannerHelper;
import com.google.common.collect.Iterators;
import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;
@@ -165,6 +166,20 @@ private void cleanUpInstance() {
if (isOwnedInstance) {
// Delete the instance, which implicitly drops all databases in it.
try {
if (!EmulatorSpannerHelper.isUsingEmulator()) {
// Backups must be explicitly deleted before the instance may be deleted.
logger.log(
Level.FINE, "Deleting backups on test instance {0}", testHelper.getInstanceId());
for (Backup backup :
testHelper
.getClient()
.getDatabaseAdminClient()
.listBackups(testHelper.getInstanceId().getInstance())
.iterateAll()) {
logger.log(Level.FINE, "Deleting backup {0}", backup.getId());
backup.delete();
}
}
logger.log(Level.FINE, "Deleting test instance {0}", testHelper.getInstanceId());
instanceAdminClient.deleteInstance(testHelper.getInstanceId().getInstance());
logger.log(Level.INFO, "Deleted test instance {0}", testHelper.getInstanceId());

0 comments on commit ff571b0

Please sign in to comment.