Skip to content

Commit ff571b0

Browse files
authored
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
1 parent b3c96f2 commit ff571b0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntegrationTestEnv.java

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Preconditions.checkState;
2020

2121
import com.google.api.gax.longrunning.OperationFuture;
22+
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
2223
import com.google.cloud.spanner.testing.RemoteSpannerHelper;
2324
import com.google.common.collect.Iterators;
2425
import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;
@@ -165,6 +166,20 @@ private void cleanUpInstance() {
165166
if (isOwnedInstance) {
166167
// Delete the instance, which implicitly drops all databases in it.
167168
try {
169+
if (!EmulatorSpannerHelper.isUsingEmulator()) {
170+
// Backups must be explicitly deleted before the instance may be deleted.
171+
logger.log(
172+
Level.FINE, "Deleting backups on test instance {0}", testHelper.getInstanceId());
173+
for (Backup backup :
174+
testHelper
175+
.getClient()
176+
.getDatabaseAdminClient()
177+
.listBackups(testHelper.getInstanceId().getInstance())
178+
.iterateAll()) {
179+
logger.log(Level.FINE, "Deleting backup {0}", backup.getId());
180+
backup.delete();
181+
}
182+
}
168183
logger.log(Level.FINE, "Deleting test instance {0}", testHelper.getInstanceId());
169184
instanceAdminClient.deleteInstance(testHelper.getInstanceId().getInstance());
170185
logger.log(Level.INFO, "Deleted test instance {0}", testHelper.getInstanceId());

0 commit comments

Comments
 (0)