Skip to content

Commit 01eb3d5

Browse files
authored
fix: presubmit failure for samples backups test (#2492)
* fix: presubmit failure for samples backups test * gemini review
1 parent c624619 commit 01eb3d5

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

protos/protos.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/protos.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/system-test/spanner.test.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,27 @@ const GAX_OPTIONS = {
112112
},
113113
};
114114

115-
const delay = async test => {
115+
async function cleanupDatabase(instanceId, databaseId) {
116+
const database = spanner.instance(instanceId).database(databaseId);
117+
try {
118+
await database.delete();
119+
} catch (err) {
120+
// ignore the error in case the database doesn't exists
121+
if (err.code !== 5) {
122+
throw err;
123+
}
124+
}
125+
}
126+
127+
const delay = async (test, cleanupFn = null) => {
116128
const retries = test.currentRetry();
117129
// No retry on the first failure.
118130
if (retries === 0) return;
131+
132+
// run cleanup for database, provided
133+
if (cleanupFn) {
134+
await cleanupFn();
135+
}
119136
// See: https://cloud.google.com/storage/docs/exponential-backoff
120137
const ms = Math.pow(2, retries) + Math.random() * 1000;
121138
return new Promise(done => {
@@ -1518,7 +1535,9 @@ describe('Autogenerated Admin Clients', () => {
15181535
// we'll have to retry.
15191536
this.retries(5);
15201537
// Delay the start of the test, if this is a retry.
1521-
await delay(this.test);
1538+
await delay(this.test, async () => {
1539+
await cleanupDatabase(INSTANCE_ID, RESTORE_DATABASE_ID);
1540+
});
15221541

15231542
const output = execSync(
15241543
`${backupsCmd} restoreBackup ${INSTANCE_ID} ${RESTORE_DATABASE_ID} ${BACKUP_ID} ${PROJECT_ID}`,
@@ -1539,7 +1558,9 @@ describe('Autogenerated Admin Clients', () => {
15391558
// we'll have to retry.
15401559
this.retries(5);
15411560
// Delay the start of the test, if this is a retry.
1542-
await delay(this.test);
1561+
await delay(this.test, async () => {
1562+
await cleanupDatabase(INSTANCE_ID, ENCRYPTED_RESTORE_DATABASE_ID);
1563+
});
15431564

15441565
const key = await getCryptoKey(KEY_LOCATION_ID1);
15451566

@@ -2510,7 +2531,9 @@ describe('Autogenerated Admin Clients', () => {
25102531
// we'll have to retry.
25112532
this.retries(5);
25122533
// Delay the start of the test, if this is a retry.
2513-
await delay(this.test);
2534+
await delay(this.test, async () => {
2535+
await cleanupDatabase(MULTI_REGION_INSTANCE_ID, MR_CMEK_RESTORED);
2536+
});
25142537

25152538
const output = execSync(
25162539
`node backups-restore-with-multiple-kms-keys.js \

0 commit comments

Comments
 (0)