Skip to content

test(core): update gcp-metadata runtime and ensure HTTP/2 cleanup - #9915

Draft
quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:test/core-system-test-runtime-and-cleanup
Draft

quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:test/core-system-test-runtime-and-cleanup

Conversation

@quirogas

Copy link
Copy Markdown
Contributor

Description

Updates Cloud Functions test runtime to Node 22 and hardens object cleanup.

Impact

Keeps system tests on supported Node runtimes and prevents leaked objects.

Changes

  • Update --runtime=nodejs20 to --runtime=nodejs22 in core/packages/gcp-metadata/system-test/system.ts.
  • Wrap multi-part upload assertions and DELETE cleanup in try / finally in core/packages/nodejs-googleapis-common/system-test/test.http2.ts.

Testing

  • Ran TypeScript type-checking and linting in core/packages/gcp-metadata and core/packages/nodejs-googleapis-common.

Alternatives

  • Leaving --runtime=nodejs20 targets an end-of-life runtime, and running object cleanup outside finally leaves test objects behind when assertions fail.

@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 updates the Node.js runtime to version 22 in the GCP metadata system tests and wraps HTTP/2 system test assertions in a try-finally block to ensure resource cleanup. The review feedback recommends enhancing the try-finally implementation to prevent secondary cleanup errors from masking the primary assertion failures, which makes debugging in CI easier.

Comment on lines +126 to +141
try {
assert.ok(result.data);
assert.strictEqual(result.status, 200);
} finally {
await createAPIRequest<FakeParams>({
options: {
url: `${url}/${name}`,
http2: true,
method: 'DELETE',
},
params: {},
requiredParams: [],
pathParams: [],
context,
});
}

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.

medium

If the assertions fail (for example, if result.status is not 200), the resource might not have been successfully created or might be in an unexpected state. In such cases, the subsequent DELETE request in the finally block will likely fail (e.g., with a 404 Not Found error). This secondary cleanup error will then be thrown from the finally block, masking the original assertion failure and making debugging in CI significantly harder.

To prevent this, we can track whether the main test body failed and only propagate the cleanup error if the test itself succeeded.

    let testFailed = false;
    try {
      assert.ok(result.data);
      assert.strictEqual(result.status, 200);
    } catch (err) {
      testFailed = true;
      throw err;
    } finally {
      try {
        await createAPIRequest<FakeParams>({
          options: {
            url: `${url}/${name}`,
            http2: true,
            method: 'DELETE',
          },
          params: {},
          requiredParams: [],
          pathParams: [],
          context,
        });
      } catch (cleanupErr) {
        if (!testFailed) {
          throw cleanupErr;
        }
      }
    }

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant