Skip to content

Commit

Permalink
fix: Deflake Backup integration tests due to deleteBackup timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
steveniemitz committed Feb 8, 2024
1 parent 7c438c6 commit fd67db6
Showing 1 changed file with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.google.api.gax.batching.Batcher;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.DeadlineExceededException;
import com.google.cloud.Policy;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
Expand Down Expand Up @@ -51,6 +52,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -104,6 +106,20 @@ public static void tearDownClass() {
}
}

private static void deleteBackupIgnoreErrors(
BigtableTableAdminClient tableAdmin, String clusterId, String backupId) {
try {
tableAdmin.deleteBackup(clusterId, backupId);
} catch (DeadlineExceededException ex) {
LOGGER.log(Level.WARNING, "Error deleting backup", ex);
// Don't rethrow
}
}

private void deleteBackupIgnoreErrors(String clusterId, String backupId) {
deleteBackupIgnoreErrors(tableAdmin, clusterId, backupId);
}

@Test
public void createAndGetBackupTest() {
String backupId = prefixGenerator.newPrefix();
Expand Down Expand Up @@ -146,7 +162,7 @@ public void createAndGetBackupTest() {
.isAnyOf(Backup.State.CREATING, Backup.State.READY);

} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
}
}

Expand All @@ -166,8 +182,8 @@ public void listBackupTest() {
.that(response)
.containsAtLeast(backupId1, backupId2);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId1);
tableAdmin.deleteBackup(targetCluster, backupId2);
deleteBackupIgnoreErrors(targetCluster, backupId1);
deleteBackupIgnoreErrors(targetCluster, backupId2);
}
}

Expand All @@ -183,24 +199,19 @@ public void updateBackupTest() {
Backup backup = tableAdmin.updateBackup(req);
assertWithMessage("Incorrect expire time").that(backup.getExpireTime()).isEqualTo(expireTime);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
}
}

@Test
public void deleteBackupTest() throws InterruptedException {
public void deleteBackupTest() {
String backupId = prefixGenerator.newPrefix();

tableAdmin.createBackup(createBackupRequest(backupId));
tableAdmin.deleteBackup(targetCluster, backupId);

try {
for (int i = 0; i < BACKOFF_DURATION.length; i++) {
tableAdmin.getBackup(targetCluster, backupId);

LOGGER.info("Wait for " + BACKOFF_DURATION[i] + " seconds for deleting backup " + backupId);
Thread.sleep(BACKOFF_DURATION[i] * 1000);
}
tableAdmin.getBackup(targetCluster, backupId);
fail("backup was not deleted.");
} catch (ApiException ex) {
assertWithMessage("Incorrect exception type")
Expand Down Expand Up @@ -240,7 +251,7 @@ public void restoreTableTest() throws InterruptedException, ExecutionException {
.isEqualTo(restoredTableId);
}
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
tableAdmin.deleteTable(restoredTableId);
}
}
Expand Down Expand Up @@ -298,7 +309,7 @@ public void crossInstanceRestoreTest()
destTableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
destTableAdmin.getTable(restoredTableId);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
instanceAdmin.deleteInstance(targetInstance);
}
}
Expand Down Expand Up @@ -340,8 +351,8 @@ public void copyBackupTest()
.isAnyOf(Backup.State.CREATING, Backup.State.READY);

} finally {
tableAdmin.deleteBackup(targetCluster, copiedBackupId);
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, copiedBackupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
}
}

Expand Down Expand Up @@ -395,8 +406,8 @@ public void crossInstanceCopyBackupTest()
.isAnyOf(Backup.State.CREATING, Backup.State.READY);

} finally {
destTableAdmin.deleteBackup(destCluster, copiedBackupId);
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(destTableAdmin, destCluster, copiedBackupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
instanceAdmin.deleteInstance(destInstance);
}
}
Expand Down Expand Up @@ -430,7 +441,7 @@ public void backupIamTest() {
"bigtable.backups.restore");
assertThat(permissions).hasSize(4);
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
deleteBackupIgnoreErrors(targetCluster, backupId);
}
}

Expand Down

0 comments on commit fd67db6

Please sign in to comment.