Skip to content

fix(genai): ensure resource cleanup and fix async execution in content-cache tests - #4403

Open
angelcaamal wants to merge 2 commits into
mainfrom
fix-content-cache-test
Open

fix(genai): ensure resource cleanup and fix async execution in content-cache tests#4403
angelcaamal wants to merge 2 commits into
mainfrom
fix-content-cache-test

Conversation

@angelcaamal

@angelcaamal angelcaamal commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes several execution and lifecycle issues in the genai/content-cache tests.

Previously, the tests had the following issues:

  1. Skipped executions: The describe block was marked as async, which is not supported by Mocha and caused the suite to exit early or register 0 passing tests.
  2. Broken retry delays: The retry delay function was placed inside a before hook. Since before only runs once per suite, test retries were not getting the intended backoff delay.
  3. Orphaned resources: If a test failed in the middle of the suite (e.g., during update or use), the delete test was never reached, leaving orphaned caches in the GCP project.

Fixes Internal: b/548501421

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Aug 18, 2026

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

Copy link
Copy Markdown
Contributor

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 refactors the content-cache-create-use-update-delete.test.js test suite by removing the async keyword from the describe block, moving the initial delay into a before hook, and adding an after hook to ensure the content cache is cleaned up. Feedback was provided pointing out that using a before hook for the retry delay will only run once and won't execute on test retries. It is recommended to use a beforeEach hook with this.currentTest instead.

Comment thread genai/content-cache/test/content-cache-create-use-update-delete.test.js Outdated

@Kef131 Kef131 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks solid to me 👍

@XrossFox XrossFox left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@angelcaamal
angelcaamal marked this pull request as ready for review August 18, 2026 16:32
@angelcaamal
angelcaamal requested review from a team as code owners August 18, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants