Skip to content

chore(gax): resolve linter warnings in apiCallable unit tests - #9278

Closed
shivanee-p wants to merge 2 commits into
shivaneep-o11y-http-tracingfrom
shivaneep-apicallable-linter-fixes
Closed

chore(gax): resolve linter warnings in apiCallable unit tests#9278
shivanee-p wants to merge 2 commits into
shivaneep-o11y-http-tracingfrom
shivaneep-apicallable-linter-fixes

Conversation

@shivanee-p

@shivanee-p shivanee-p commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Update Promises in apiCallable.ts to use modern async/await patterns

@shivanee-p
shivanee-p added this pull request to stack #9275 September 9, 2026 21:51

@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 several unit tests in apiCallable.ts to use async/await syntax instead of callbacks and promise chains, improving readability and modernizing the test suite. The review feedback focuses on simplifying the assert.rejects assertions by passing the promises directly rather than wrapping them in redundant async functions, utilizing error constructors for type assertions, and removing unnecessary non-null assertion operators.

Comment on lines +1121 to +1130
await assert.rejects(
async () => {
await promise;
},
(err: GoogleError) => {
assert(err instanceof GoogleError);
assert.strictEqual(err.code, status.CANCELLED);
done();
});
promise.cancel();
return true;
},
);

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

Node's assert.rejects accepts a Promise directly as its first argument. Wrapping the promise in an async function is redundant and can be simplified.

    await assert.rejects(
      promise,
      (err: GoogleError) => {
        assert(err instanceof GoogleError);
        assert.strictEqual(err.code, status.CANCELLED);
        return true;
      },
    );

Comment on lines +1164 to +1166
await assert.rejects(async () => {
await promise;
});

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

Node's assert.rejects accepts a Promise directly as its first argument. Wrapping the promise in an async function is redundant and can be simplified.

    await assert.rejects(promise);

Comment on lines +1266 to +1274
await assert.rejects(
async () => {
await promise;
},
(err: Error) => {
assert(err instanceof Error);
done();
});
return true;
},
);

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

Node's assert.rejects accepts a Promise directly as its first argument, and can also accept an error constructor (like Error) as the second argument to assert the type of the rejected error. This simplifies the assertion significantly.

    await assert.rejects(promise, Error);

Comment on lines +1470 to +1491
await assert.rejects(
async () => {
await apiCall({}, undefined);
},
(err: GoogleError) => {
assert(err instanceof Error);
assert.strictEqual(err!.code, FAKE_STATUS_CODE_1);
assert(err!.note);
const now = new Date();
assert(
now.getTime() - startTime.getTime() >= backoff.totalTimeoutMillis!,
);
const callsLowerBound =
backoff.totalTimeoutMillis! /
(backoff.maxRetryDelayMillis + backoff.maxRpcTimeoutMillis!);
const callsUpperBound =
backoff.totalTimeoutMillis! / backoff.initialRetryDelayMillis;
assert(spy.callCount > callsLowerBound);
assert(spy.callCount < callsUpperBound);
return true;
},
);

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

Node's assert.rejects accepts a Promise directly as its first argument. Additionally, since err is typed as GoogleError (which is non-nullable), the non-null assertion operator (!) is redundant and can be removed.

    await assert.rejects(
      apiCall({}, undefined),
      (err: GoogleError) => {
        assert(err instanceof Error);
        assert.strictEqual(err.code, FAKE_STATUS_CODE_1);
        assert(err.note);
        const now = new Date();
        assert(
          now.getTime() - startTime.getTime() >= backoff.totalTimeoutMillis!,
        );
        const callsLowerBound =
          backoff.totalTimeoutMillis! /
          (backoff.maxRetryDelayMillis + backoff.maxRpcTimeoutMillis!);
        const callsUpperBound =
          backoff.totalTimeoutMillis! / backoff.initialRetryDelayMillis;
        assert(spy.callCount > callsLowerBound);
        assert(spy.callCount < callsUpperBound);
        return true;
      },
    );

@shivanee-p
shivanee-p force-pushed the shivaneep-apicallable-linter-fixes branch from e2c6424 to 7d14d55 Compare September 10, 2026 18:37
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-http-tracing branch from 23228f6 to e2b5e2e Compare September 10, 2026 18:37
@shivanee-p shivanee-p closed this Sep 10, 2026
@shivanee-p
shivanee-p deleted the shivaneep-apicallable-linter-fixes branch September 10, 2026 18:39
@shivanee-p
shivanee-p removed this pull request from stack #9275 September 10, 2026 18:41
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