Skip to content

Conversation

@alkatrivedi
Copy link
Contributor

@alkatrivedi alkatrivedi commented Jan 7, 2026

The restore backup tests are failing because of timeouts.

Since the database is created and the restore operation getting timeout, the automatic retry logic fails with a DATABASE ALREADY EXISTS error. A cleanup logic has been added to delete the existing database before the retry logic triggers.

@alkatrivedi alkatrivedi requested review from a team as code owners January 7, 2026 03:13
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/nodejs-spanner API. samples Issues that are directly related to samples. labels Jan 7, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @alkatrivedi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves presubmit failures occurring in the Spanner backup samples tests. The core change involves implementing a robust cleanup mechanism that ensures databases are properly deleted before test retries. This prevents resource conflicts and ensures that each test run, especially after a failure, starts from a clean and predictable state, thereby improving the overall reliability and stability of the test suite.

Highlights

  • New Database Cleanup Function: Introduced a new asynchronous utility function, cleanupDatabase, to programmatically delete specified Spanner databases, enhancing resource management within tests.
  • Enhanced Test Retry Logic: Modified the existing delay utility function to accept an optional cleanupFn parameter, allowing for custom cleanup operations to be executed before a test is retried.
  • Improved Test Reliability for Backups: Integrated the new cleanupDatabase function into the retry logic of several Spanner backup and restore tests. This ensures that databases like RESTORE_DATABASE_ID, ENCRYPTED_DATABASE_ID, and MR_CMEK_RESTORED are properly cleaned up before test retries, preventing presubmit failures caused by lingering resources.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to clean up resources before retrying a failed test, which is a great way to improve test reliability. A new cleanupDatabase function has been added, and the delay function used for retries has been updated to accept a cleanup function. This is then applied to several backup restoration tests.

The implementation is mostly correct, but I've found one critical issue in one of the tests where the wrong database ID is being used for cleanup, which would prevent the test from recovering correctly on a retry. Please see the specific comment for details.

Comment on lines 1554 to 1556
await delay(this.test, async () => {
await cleanupDatabase(INSTANCE_ID, ENCRYPTED_DATABASE_ID);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

It seems there's a mismatch in the database being cleaned up. The test 'should restore database from a backup using an encryption key' restores to ENCRYPTED_RESTORE_DATABASE_ID, but the cleanup function passed to delay is attempting to clean up ENCRYPTED_DATABASE_ID. To ensure the correct database is cleaned up on retry, you should use ENCRYPTED_RESTORE_DATABASE_ID in the cleanupDatabase call.

Suggested change
await delay(this.test, async () => {
await cleanupDatabase(INSTANCE_ID, ENCRYPTED_DATABASE_ID);
});
await delay(this.test, async () => {
await cleanupDatabase(INSTANCE_ID, ENCRYPTED_RESTORE_DATABASE_ID);
});

@alkatrivedi alkatrivedi force-pushed the fix-samples-presubmit branch from 3d4ba82 to 9d58d9a Compare January 7, 2026 03:28
@alkatrivedi
Copy link
Contributor Author

/gemini

@gemini-code-assist
Copy link

It looks like you tried to invoke a command, but the correct syntax is /gemini <command> or @gemini-code-assist <command>. If you intended to ask for help, you can use /gemini help.

For your convenience, here is the help message:

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

surbhigarg92
surbhigarg92 previously approved these changes Jan 7, 2026
@alkatrivedi
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a cleanup mechanism for retrying failing tests, specifically for tests that restore Spanner backups. A cleanupDatabase function is added and integrated into the existing delay function used for test retries. This ensures that any partially created databases from a failed test run are deleted before a retry attempt. My review includes a suggestion to make the cleanupDatabase function more robust by handling cases where the database might not exist, preventing unhandled errors that could disrupt the test retry logic.

Comment on lines 115 to 118
async function cleanupDatabase(instanceId, databaseId) {
const database = spanner.instance(instanceId).database(databaseId);
await database.delete();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The cleanupDatabase function could fail if the database it's trying to delete doesn't exist. This might happen if the test fails before the database is created. An unhandled exception here would prevent the test from retrying correctly. It's better to wrap the database.delete() call in a try...catch block and ignore NOT_FOUND errors (gRPC status code 5).

async function cleanupDatabase(instanceId, databaseId) {
  const database = spanner.instance(instanceId).database(databaseId);
  try {
    await database.delete();
  } catch (err) {
    // The database may not exist if the test failed before it was created.
    // In that case, we can ignore the error.
    if (err.code !== 5) { // 5 = grpc.status.NOT_FOUND
      throw err;
    }
  }
}

@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jan 7, 2026
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 7, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 7, 2026
@surbhigarg92 surbhigarg92 merged commit 01eb3d5 into main Jan 7, 2026
24 of 25 checks passed
@surbhigarg92 surbhigarg92 deleted the fix-samples-presubmit branch January 7, 2026 15:22
gcf-merge-on-green bot pushed a commit that referenced this pull request Jan 9, 2026
🤖 I have created a release *beep* *boop*
---


## [8.4.0](https://togithub.com/googleapis/nodejs-spanner/compare/v8.3.1...v8.4.0) (2026-01-09)


### Features

* Add a ClientContext field to Spanner requests ([#2493](https://togithub.com/googleapis/nodejs-spanner/issues/2493)) ([37504ad](https://togithub.com/googleapis/nodejs-spanner/commit/37504adcc37a7e95acfb2530313ff783d0c1fe7d))
* Exposing total CPU related fields in AutoscalingConfig ([#2490](https://togithub.com/googleapis/nodejs-spanner/issues/2490)) ([508f0ff](https://togithub.com/googleapis/nodejs-spanner/commit/508f0ff95636b004f4200522018a199263eda8ca))
* **spanner:** Support for type UUID ([#2482](https://togithub.com/googleapis/nodejs-spanner/issues/2482)) ([0047e94](https://togithub.com/googleapis/nodejs-spanner/commit/0047e9407d86521571626c69011b70307f83f8ba))


### Bug Fixes

* **deps:** Update dependency google-gax to v5.0.6 ([#2452](https://togithub.com/googleapis/nodejs-spanner/issues/2452)) ([f9e6b86](https://togithub.com/googleapis/nodejs-spanner/commit/f9e6b86ff4da03110642c17e5ebc8fac8d903d3a))
* Flaky metric test ([#2472](https://togithub.com/googleapis/nodejs-spanner/issues/2472)) ([e169cc5](https://togithub.com/googleapis/nodejs-spanner/commit/e169cc5344d38812b1ebf20c7a987715a73d6f79))
* Memory leak and deadlock due to error event in multiplexed session ([#2477](https://togithub.com/googleapis/nodejs-spanner/issues/2477)) ([c624619](https://togithub.com/googleapis/nodejs-spanner/commit/c624619a3960892b1d2d412ff79faa5a74de45df))
* Presubmit failure for samples backups test ([#2492](https://togithub.com/googleapis/nodejs-spanner/issues/2492)) ([01eb3d5](https://togithub.com/googleapis/nodejs-spanner/commit/01eb3d5801ddb21517f185b9d585fbce4fa1475c))
* Type check for key in deleteRows ([#2486](https://togithub.com/googleapis/nodejs-spanner/issues/2486)) ([7347a16](https://togithub.com/googleapis/nodejs-spanner/commit/7347a1628ad8635b8f84b36ad1d3850b78862ac7))
* Type mismatch in Snapshot.run error handler ([#2487](https://togithub.com/googleapis/nodejs-spanner/issues/2487)) ([4ac0360](https://togithub.com/googleapis/nodejs-spanner/commit/4ac036047e3a03c073300f288c746389a38d8e42))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/nodejs-spanner API. samples Issues that are directly related to samples. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants