Skip to content

test(functions): stub the default compute service account lookup - #11162

Open
IzaakGough wants to merge 3 commits into
mainfrom
@invertase/fix-spec-compute-api-flake
Open

IzaakGough wants to merge 3 commits into
mainfrom
@invertase/fix-spec-compute-api-flake

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes flaky tests

  • Stubbed gce.getDefaultServiceAccount in checkIam.spec.ts and fabricator.spec.ts. Both specs left it unstubbed, so any test needing the default compute account made a live request to compute.googleapis.com and raced mocha's 2s timeout. This is the source of the checkIam timeouts currently failing on main.
  • Replaced the live lookup inside a fabricator.spec.ts assertion with a literal. The expectation previously called the real API to build its own expected value.

Reproduced deterministically with COMPUTE_URL=https://10.255.255.1: before, 10 checkIam tests and 3 fabricator tests time out; after, both files pass with no network. checkIam.spec.ts drops from 2s to 16ms. Verified the assertions still pin the account name by pointing them at a wrong address and watching them fail.

No production code changes.

checkIam.spec.ts and fabricator.spec.ts left gce.getDefaultServiceAccount
unstubbed, so every test needing the default compute account made a live
request to compute.googleapis.com and raced mocha's 2s timeout. These are
the checkIam timeouts currently failing on main.

@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 stubs the Google Compute Engine (GCE) API's getDefaultServiceAccount method in the unit tests for checkIam and fabricator. This prevents the tests from making network requests to the Compute API, resolving potential race conditions with Mocha's 2-second timeout. I have no feedback to provide as the changes are appropriate and there are no review comments.

@IzaakGough
IzaakGough marked this pull request as ready for review September 25, 2026 10:55
A stub that resolves a fixed address no longer pins that callers pass the
project number to getDefaultServiceAccount. Use callsFake so the tests keep
asserting that, and stub the same lookup in the apphosting secrets spec,
which still reached the Compute API over the network.

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.

2 participants