Skip to content

test: Use separate transports to fix flakiness - #4752

Merged
gmlewis merged 2 commits into
google:masterfrom
gmlewis:fix-scrape-flake
Dec 1, 2026
Merged

gmlewis merged 2 commits into
google:masterfrom
gmlewis:fix-scrape-flake

Conversation

@gmlewis

@gmlewis gmlewis commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes: https://github.com/google/go-github/actions/runs/46658354075
and other flaky tests by ensuring that each test gets its own transport.

Why it happens

It's a race between parallel tests sharing http.DefaultTransport:

  • scrape/scrape_test.go:26 does client = NewClient(nil), and NewClient leaves Transport nil (scrape/scrape.go:55-59), so every test client uses the global http.DefaultTransport.
  • Every test in the package calls t.Parallel().
  • When any test finishes, t.Cleanup(server.Close) runs, and httptest.Server.Close() deliberately calls http.DefaultTransport.(closeIdleTransport).CloseIdleConnections() "to help out" users of the standard transport (Go source: net/http/httptest/server.go:512-515).

Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (5175b68) to head (57f9684).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4752      +/-   ##
==========================================
- Coverage   98.64%   98.63%   -0.01%     
==========================================
  Files         204      204              
  Lines       19165    19165              
==========================================
- Hits        18905    18904       -1     
- Misses        260      261       +1     

☔ View full report in Codecov by Harness.
📢 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.

@gmlewis
gmlewis merged commit 592f43f into google:master Dec 1, 2026
14 of 15 checks passed
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