Skip to content

feat(ci): improve test performance, fix failing tests - #9021

Open
bshaffer wants to merge 22 commits into
mainfrom
improve-test-performance
Open

feat(ci): improve test performance, fix failing tests#9021
bshaffer wants to merge 22 commits into
mainfrom
improve-test-performance

Conversation

@bshaffer

@bshaffer bshaffer commented Jul 29, 2026

Copy link
Copy Markdown
Contributor
  • Conditional Test Sharding: Dynamically shards tests when a large number of packages are modified. Adds a job that rolls up shard results to satisfy branch protection. For what this looks like with just ONE package modified, see chore: test sharding with one package #9027

  • Pipeline Speed: Reduces GitHub Action checkout fetch-depth to 2, which saves ~4 minutes for each shard

  • Clean CI Logs: Switches Mocha to use dot reporter and removes accidental console.log from the Firestore conformance tests.

  • Disambiguous Workflow Names: Renames conformance-test and conformance to bigtable-conformance and storage-conformance respectively.

  • Test Fixes:

    1. Increases the pack-n-play test timeout to accommodate npm install
    2. unwraps native fetch errors in gcp-metadata to suppress ECONNREFUSED warnings
    3. replaces url.parse() with new URL() in nodejs-googleapis-common to fix Mocha test crashes
    4. fixes race-condition in bigtable client-side exporter.
  • Confirm that it's okay to skip pack-and-play unit tests on Windows (as these alone add 5-10 minutes).

Comment on lines +64 to +68
# echo "skipping trigger of tests for now: tracking in #7540"
echo "change detected in ci, we should test everything"
echo "result of git diff ${GIT_DIFF_ARG} ci:"
git diff ${GIT_DIFF_ARG} ci
GIT_DIFF_ARG=""

@bshaffer bshaffer Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As tests now take ~30 minutes (down from 2 hours), we can reenable this and close #7540.

Once we add PNPM workspaces and turbo caching, this number goes down to ~15!!

@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 parallelizes test execution and adds sharding support in the CI conditional test runner, configures the Mocha reporter and silences pnpm installation in the single test runner, and updates mock discovery URLs in the googleapis-common tests. A critical syntax error was identified in the conditional test runner script, where leftover loop and conditional control structures will cause the Bash script to fail.

Comment thread ci/run_conditional_tests.sh Outdated
@bshaffer
bshaffer marked this pull request as ready for review July 30, 2026 15:12
@bshaffer
bshaffer requested review from a team as code owners July 30, 2026 15:12
@bshaffer bshaffer changed the title feat(ci): improve test performance feat(ci): improve test performance, fix failing tests Jul 30, 2026
@bshaffer

Copy link
Copy Markdown
Contributor Author

@gemini-code-assist review

@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 introduces test sharding and dynamic matrix generation for GitHub Actions in the CI scripts, updates pnpm install flags, and transitions from the deprecated url.parse to the standard URL API. Additionally, it increases test timeouts, skips certain tests on Windows, handles nested error causes in gcp-metadata, and ensures startTime does not exceed endTime in Bigtable metrics. Feedback focuses on improving shell script robustness by quoting variables (BUILD_TYPE, d, and test_script) to prevent syntax or word-splitting issues, and avoiding direct mutation of the options parameter in the OpenTelemetry test stub.

Comment thread ci/run_conditional_tests.sh Outdated
Comment thread ci/run_conditional_tests.sh Outdated
Comment thread handwritten/bigtable/test/metrics-collector/gcp-metrics-handler.ts

@westarle westarle 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.

A few comments, I think this is a really great idea!


if [[ -n "${SHARD_TOTAL}" && -n "${SHARD_INDEX}" ]]; then
if (( SHARD_TOTAL > 0 && i % SHARD_TOTAL != SHARD_INDEX )); then
continue

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.

We should just keep an eye on whether there are differences between the shard durations (in case multiple "heavy" targets land in a single shard consistently.)

@bshaffer bshaffer Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've already seen this happen that Shard 0 is a little heavier, probably because of the bigtable and pack-n-play tests. If a big discrepancy emerges (right now, it seems like just a few minutes, so I am not sure it's a big concern), we could take the known longer tests and manually separate them? What are your thoughts on the best way to accomplish this?

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.

we could take the known longer tests and manually separate them

This it what I'd do.

right now, it seems like just a few minutes, so I am not sure it's a big concern

+1

# Then fetch enough history for finding the common commit.
git fetch origin main --deepen=300
# Then fetch enough history for finding the common commit.
git fetch origin main --deepen=300

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.

Can we have the action fetch the right level of detail? I think we do 2 levels in setup then immediately fill in 300 more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that 2 is sufficient for github actions, but 300 might be needed for kokoro (which is why the conditional here exists). The 300 is just supposed to be a sufficiently large number to ensure a common commit ancestor is found.

So I guess Im not sure what your suggestion is here.

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.

Thanks for handling the newbie questions Brent. TIL about actions/checkout synthetic commits (and also I missed the if [ -z... at the top of this diff).

I'd like all these scripts to be hermetic, and have things work like your actions work (operator fetches the right depth and passes the GIT_DIFF_ARG). Today, if I set GIT_DIFF_ARG but fail to fetch it fails, and if I don't set GIT_DIFF_ARG it can waste some time if I already fetched what I know I need.

Here's a practical fix for now:

  • Add a new "strict" flag or variable --strict/STRICT to the script and pass it from the action
  • If "strict" is set, GIT_DIFF_ARG must be set and git diff --quiet ${GIT_DIFF_ARG} must return 0 or 1.
  • The test on line 34 becomes "if not strict".

Then we can visit GCB builds later to the model you're introducing for actions here.

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.

could this be in another PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bigtable unit tests were failing, so I added these changes to fix them... however I'm not 100% sure THIS specific file update is needed (I suspect it is). I can verify!

run_id: context.runId,
});
const nodeVersion = '${{ matrix.node-version }}';
const shardJobs = jobs.filter(j => j.name.includes(`units (Node ${nodeVersion},`));

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.

can we reuse test_dirs from setup?

it('should run tests', async () => {
it('should run tests', async function () {
this.timeout(120000); // 2 minutes
if (process.platform === 'win32') {

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.

I'd be more comfortable doing this after we set up a postsubmit for the coverage. It seems like Windows would cause more problems in packaging...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly after testing, this did not affect performance that much, and windows STILL took 30-40 minutes, so I think removing it is the right call

Comment thread ci/run_single_test.sh
echo "pnpm install --ignore-scripts --engine-strict --prod --pnpmfile \"${PNPMFILE_PATH}\"; pnpm install --pnpmfile \"${PNPMFILE_PATH}\""
pnpm install --ignore-scripts --engine-strict --prod --pnpmfile "${PNPMFILE_PATH}"; pnpm install --pnpmfile "${PNPMFILE_PATH}"
echo "pnpm install --reporter=silent --engine-strict --pnpmfile \"${PNPMFILE_PATH}\""
pnpm install --reporter=silent --engine-strict --pnpmfile "${PNPMFILE_PATH}"

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.

Are errors still reported with --reporter=silent?

@westarle westarle 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.

Also, would you be OK with breaking the test fixes out to their own little PRs?

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