Repository navigation
Conversation
There was a problem hiding this comment.
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.
| 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, | ||
| }); | ||
| } |
There was a problem hiding this comment.
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;
}
}
}
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
--runtime=nodejs20to--runtime=nodejs22incore/packages/gcp-metadata/system-test/system.ts.DELETEcleanup intry / finallyincore/packages/nodejs-googleapis-common/system-test/test.http2.ts.Testing
core/packages/gcp-metadataandcore/packages/nodejs-googleapis-common.Alternatives
--runtime=nodejs20targets an end-of-life runtime, and running object cleanup outsidefinallyleaves test objects behind when assertions fail.