Skip to content

fix: update go-test#1187

Open
gammazero wants to merge 10 commits into
mainfrom
update-go-test
Open

fix: update go-test#1187
gammazero wants to merge 10 commits into
mainfrom
update-go-test

Conversation

@gammazero

@gammazero gammazero commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🧪 Tests use new go-test and math/rand/v2

The new go-test is upgraded to use math/rand/v2 in all of its packages. The go-test/random package now allows reuse of the random number generator for more efficiently generating sets of random values.

Additionally, the go-test/random package removes support for a global seed for the random number generator. This led to the possibility of multiple tests interferring with each other when generating deterministic values. For the same reason, support for a global sequence was removed. This breakage could be intermittent and difficult to debug, depending on the how/which tests ran at the same time.

Since the underlying pseudo-random number generator was changed in the go-test module, the data generated for a given seed also changed. This required updating tests that relied on seeding the generator and getting expected values.

  • Use new go-test/random API
    • no global seed values
    • reuse generator where appropriate
  • Migrate from /math/rand' to /math/rand/v2`
    • random seeds are now [32]byte and not uint64
    • use StringToSeed or Uint64ToSeed to create random seeds for deterministic output

gammazero added 2 commits July 9, 2026 05:38
Replace all use of `math/rand` with `math/rand/v2`
@socket-security

socket-security Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgithub.com/​ipfs/​go-test@​v0.3.0 ⏵ v0.4.0100 +1100100100100

View full report

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.84%. Comparing base (1bb7b20) to head (5ecaf9b).

Files with missing lines Patch % Lines
examples/bitswap-transfer/main.go 0.00% 3 Missing ⚠️
autoconf/client.go 0.00% 1 Missing ⚠️
autoconf/expansion.go 0.00% 1 Missing ⚠️
bitswap/testnet/rate_limit_generators.go 0.00% 1 Missing ⚠️
gateway/blockstore.go 0.00% 1 Missing ⚠️
gateway/value_store.go 0.00% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1187      +/-   ##
==========================================
- Coverage   63.87%   63.84%   -0.03%     
==========================================
  Files         269      269              
  Lines       27078    27073       -5     
==========================================
- Hits        17297    17286      -11     
- Misses       8073     8076       +3     
- Partials     1708     1711       +3     
Files with missing lines Coverage Δ
...wap/client/internal/session/peerresponsetracker.go 95.45% <ø> (ø)
bitswap/client/internal/session/sessionwants.go 92.13% <100.00%> (ø)
...itswap/testnet/internet_latency_delay_generator.go 88.88% <100.00%> (ø)
bootstrap/bootstrap.go 34.23% <ø> (ø)
chunker/gen/main.go 0.00% <ø> (ø)
gateway/backend_car_fetcher.go 80.26% <100.00%> (-0.26%) ⬇️
ipld/unixfs/test/utils.go 50.94% <100.00%> (ø)
peering/peering.go 73.97% <100.00%> (ø)
routing/mock/centralized_server.go 100.00% <100.00%> (ø)
util/util.go 21.05% <ø> (+2.00%) ⬆️
... and 6 more

... and 11 files with indirect coverage changes

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

@gammazero gammazero marked this pull request as ready for review July 14, 2026 14:15
@gammazero gammazero requested review from a team and lidel as code owners July 14, 2026 14:15
lidel added 3 commits July 14, 2026 19:51
The bytehash table in chunker/buzhash.go was generated with math/rand
seeded by NewSource(0). Switching gen to math/rand/v2 made it print a
different table, so re-running it and pasting the output would have
changed buzhash chunk boundaries, and with them the CID of anything
chunked with buzhash. Pin gen back to the old source and say why.
The remote blockstore, CAR fetcher, and value store each held their own
*rand.Rand and used it to pick a URL on every request. A *rand.Rand
cannot be used from more than one goroutine, so a gateway serving
requests in parallel was racing. Use the top-level math/rand/v2
functions instead, which are safe to share, and drop the seeding code.
Record the removal of util.NewSeededRand and NewTimeSeededRand, which
were exported, and the gateway race fix. Fix two typos in the go-test
entry and say what dropping the global seed is good for. Note on
sharedRNG that a random.Random cannot be shared between goroutines.

@lidel lidel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, removes a whole class of cross-test interference. I pushed three commits on top, CI is green:

  • c7a2307 fix(chunker): keep gen reproducing the committed table
    On rand/v2, chunker/gen printed a different table than the bytehash committed next to it, so (iiuc) re-running it would have moved buzhash chunk boundaries and changed CIDs. Pinned back to NewSource(0), just to avoid floating the boat. Lmk if I mistunderstood this.

  • 3b10577 fix(gateway): data race when picking a gateway url
    The remote blockstore, CAR fetcher, and value store shared a *rand.Rand across request goroutines, which isn't safe. Top-level math/rand/v2 is, and the seeding code goes away.

LGTM, once this lands, ipfs/kubo#11390 needs a re-pin from boxo main

@lidel lidel changed the title Update go test refactor: update go-test Jul 14, 2026
@lidel lidel changed the title refactor: update go-test fix: update go-test Jul 14, 2026
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