test(functions): stub the default compute service account lookup - #11162
Open
IzaakGough wants to merge 3 commits into
Open
IzaakGough wants to merge 3 commits into
IzaakGough wants to merge 3 commits into
Conversation
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.
Contributor
There was a problem hiding this comment.
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes flaky tests
gce.getDefaultServiceAccountincheckIam.spec.tsandfabricator.spec.ts. Both specs left it unstubbed, so any test needing the default compute account made a live request tocompute.googleapis.comand raced mocha's 2s timeout. This is the source of thecheckIamtimeouts currently failing on main.fabricator.spec.tsassertion 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, 10checkIamtests and 3fabricatortests time out; after, both files pass with no network.checkIam.spec.tsdrops 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.