Skip to content

Speed up CI unit tests#4081

Merged
ChrisJBurns merged 5 commits intomainfrom
speed-up-ci-unit-tests
Mar 11, 2026
Merged

Speed up CI unit tests#4081
ChrisJBurns merged 5 commits intomainfrom
speed-up-ci-unit-tests

Conversation

@ChrisJBurns
Copy link
Copy Markdown
Collaborator

@ChrisJBurns ChrisJBurns commented Mar 11, 2026

Summary

Three changes to reduce CI unit test time from ~7.5 minutes to ~2 minutes:

1. Replace go clean -cache with go clean -testcache

The test-coverage task runs go clean -cache before every test run to prevent "inconsistent NumStmt" coverage errors from stale instrumented binaries. This wipes the entire Go build cache, forcing recompilation of all 197 packages plus all dependencies from scratch — even when the GitHub Actions cache has a warm build cache available.

go clean -testcache only clears cached test results while preserving compiled packages. This is sufficient to prevent the NumStmt errors since those are caused by stale coverage-instrumented test binaries, not the general build cache.

2. Upgrade to 8-core runner

Go test compilation is CPU-bound and parallelizes well across cores. The standard ubuntu-latest runner has 4 vCPUs. Upgrading to the org's ubuntu-8cores-32gb runner (8 vCPUs, 32GB RAM) doubles available parallelism for compilation.

3. Fix coverage upload conditions

The Codecov and Coveralls upload steps had if: matrix.os == 'ubuntu-latest' which doesn't match the new runner name. Updated to startsWith(matrix.os, 'ubuntu') so coverage uploads work regardless of which Ubuntu runner variant is used.

CI evidence

Run Runner Cache strategy "Run tests with coverage" step Link
This PR ubuntu-8cores-32gb go clean -testcache 1m56s job
fix-sse PR ubuntu-latest (4-core) go clean -cache 7m18s job
streamable-session PR ubuntu-latest (4-core) go clean -cache 7m24s job
E2E rebalance PR ubuntu-latest (4-core) go clean -cache 7m26s job

~3.8x faster (7m24s average → 1m56s).

Type of change

  • Other (describe): CI performance improvement

Test plan

  • Manual testing (describe below)

Ran full task test-coverage locally with go clean -testcache — all tests pass, coverage report generates correctly, no "inconsistent NumStmt" errors. CI run on this PR confirms the 1m56s test step time on the 8-core runner.

Generated with Claude Code

The test-coverage task was running `go clean -cache` which wipes the
entire Go build cache, forcing recompilation of all 197 packages plus
dependencies from scratch on every run. This was added to prevent
"inconsistent NumStmt" coverage errors from stale instrumented binaries.

Switch to `go clean -testcache` which only clears cached test results
while preserving compiled packages. This is sufficient to prevent the
NumStmt errors since those are caused by stale test binaries, not the
build cache itself.

Local benchmarks show ~30% reduction in test time (1m28s -> 1m01s) with
the build cache warm. On CI the improvement should be significant since
the GitHub Actions cache restores the Go build cache between runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ChrisJBurns ChrisJBurns requested a review from JAORMX as a code owner March 11, 2026 00:34
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Mar 11, 2026
Go test compilation is CPU-bound and parallelizes well across cores.
Upgrading from the standard 4-core runner to 8-core should roughly
halve compilation time. Larger runners are free for public repos.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ChrisJBurns ChrisJBurns changed the title Speed up CI unit tests by using go clean -testcache Speed up CI unit tests Mar 11, 2026
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 11, 2026
The Stacklok org runner is named ubuntu-8cores-32gb, not the GitHub
standard ubuntu-latest-8-cores.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 11, 2026
The Codecov and Coveralls upload steps had `if: matrix.os ==
'ubuntu-latest'` which doesn't match the new `ubuntu-8cores-32gb`
runner. Use `startsWith(matrix.os, 'ubuntu')` so coverage uploads
work regardless of which Ubuntu runner variant is used.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 11, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.61%. Comparing base (c94afc2) to head (087002a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4081      +/-   ##
==========================================
- Coverage   68.68%   68.61%   -0.08%     
==========================================
  Files         453      453              
  Lines       46011    46011              
==========================================
- Hits        31604    31569      -35     
- Misses      11967    11999      +32     
- Partials     2440     2443       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Mar 11, 2026
@ChrisJBurns ChrisJBurns merged commit 144a4da into main Mar 11, 2026
40 checks passed
@ChrisJBurns ChrisJBurns deleted the speed-up-ci-unit-tests branch March 11, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants