Skip to content

Commit 4d21088

Browse files
authored
fix: update go-test module (#11390)
- Use new `go-test/random` API - no global seed values - reuse generator where appropriate - Fix tests to match new random data generation - update expected deterministic values - fix t0040-add-and-cat.sh - fix t0043-add-w.sh - fix t0045-ls.sh - fix t0087-repo-robust-gc.sh - fix t0270-filestore.sh - fix t0271-filestore-utils.sh - fix t0272-urlstore.sh - 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
1 parent affb148 commit 4d21088

20 files changed

Lines changed: 254 additions & 237 deletions

File tree

core/coreunix/metadata_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package coreunix
22

33
import (
44
"bytes"
5-
"context"
65
"io"
76
"testing"
87

@@ -31,11 +30,11 @@ func getDagserv(t *testing.T) ipld.DAGService {
3130
}
3231

3332
func TestMetadata(t *testing.T) {
34-
ctx := context.Background()
33+
ctx := t.Context()
3534
// Make some random node
3635
ds := getDagserv(t)
3736
data := make([]byte, 1000)
38-
_, err := io.ReadFull(random.NewRand(), data)
37+
_, err := io.ReadFull(random.New(), data)
3938
if err != nil {
4039
t.Fatal(err)
4140
}

docs/changelogs/v0.43.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This release was brought to you by the [Shipyard](https://ipshipyard.com/) team.
2323
- [🏁 `ipfs routing findprovs` no longer crashes the daemon](#-ipfs-routing-findprovs-no-longer-crashes-the-daemon)
2424
- [🛡️ Memory exhaustion fix for pubsub](#-memory-exhaustion-fix-for-pubsub)
2525
- [📊 Telemetry is now opt-in](#-telemetry-is-now-opt-in)
26+
- [🧪 Tests use new go-test and rand v2](#-tests-use-new-go-test-and-rand-v2)
2627
- [🖥️ WebUI Improvements](#-webui-improvements)
2728
- [📦️ Dependency updates](#-dependency-updates)
2829
- [📝 Changelog](#-changelog)
@@ -131,6 +132,13 @@ This flaw is already public, which is why we name it here. libp2p disclosed it a
131132

132133
The telemetry plugin is now opt-in and ships with no built-in endpoint: a node sends nothing until you set `Plugins.Plugins.telemetry.Config.Mode` to `on` and `Endpoint` to a collector you run, documented along with the payload schema in [telemetry.md](https://github.com/ipfs/kubo/blob/master/docs/telemetry.md).
133134

135+
#### 🧪 Tests use new go-test and rand v2
136+
137+
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.
138+
139+
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 setting the global seed to generate deterministic values, and breaking other tests by causing the generator to generate unexpected values. This breakage could be intermittent and difficult to debug, depending on the how/which tests ran at the same time.
140+
141+
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.
134142
#### 🖥️ WebUI Improvements
135143

136144
IPFS Web UI has been updated to [v4.13.0](https://github.com/ipfs/ipfs-webui/releases/tag/v4.13.0).

docs/examples/kubo-as-a-library/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ go 1.26.4
77
replace github.com/ipfs/kubo => ./../../..
88

99
require (
10-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09
10+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863
1111
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
1212
github.com/libp2p/go-libp2p v0.48.1-0.20260708062241-95be6665b014
1313
github.com/multiformats/go-multiaddr v0.16.1
@@ -99,7 +99,7 @@ require (
9999
github.com/ipfs/go-log/v2 v2.9.2 // indirect
100100
github.com/ipfs/go-metrics-interface v0.3.0 // indirect
101101
github.com/ipfs/go-peertaskqueue v0.8.3 // indirect
102-
github.com/ipfs/go-test v0.3.0 // indirect
102+
github.com/ipfs/go-test v0.4.1 // indirect
103103
github.com/ipfs/go-unixfsnode v1.10.5 // indirect
104104
github.com/ipld/go-car/v2 v2.17.0 // indirect
105105
github.com/ipld/go-codec-dagpb v1.7.0 // indirect

docs/examples/kubo-as-a-library/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.25.0 h1:OqNqsGZPX8zh3eFMO8Lf8EHRRnSGBMqcd
273273
github.com/ipfs-shipyard/nopfs/ipfs v0.25.0/go.mod h1:BxhUdtBgOXg1B+gAPEplkg/GpyTZY+kCMSfsJvvydqU=
274274
github.com/ipfs/bbloom v0.1.0 h1:nIWwfIE3AaG7RCDQIsrUonGCOTp7qSXzxH7ab/ss964=
275275
github.com/ipfs/bbloom v0.1.0/go.mod h1:lDy3A3i6ndgEW2z1CaRFvDi5/ZTzgM1IxA/pkL7Wgts=
276-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09 h1:jl4/IHR4IRb0QOVw6vFxUL4NRnetk1V42HIdipWu+aw=
277-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09/go.mod h1:mnR769LN1W7rDI6z1GBLmD15x4pvMdW0oWxik8j3y6g=
276+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863 h1:C3Xufr5x4qxdhlR3LKL6eKBMJQKpzeNBoGCniXv448I=
277+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863/go.mod h1:DLLtSR+2xJF3W5HRGPvL3H+y+MfBzdy1/IPlLwU0n1A=
278278
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
279279
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
280280
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
@@ -339,8 +339,8 @@ github.com/ipfs/go-metrics-interface v0.3.0 h1:YwG7/Cy4R94mYDUuwsBfeziJCVm9pBMJ6
339339
github.com/ipfs/go-metrics-interface v0.3.0/go.mod h1:OxxQjZDGocXVdyTPocns6cOLwHieqej/jos7H4POwoY=
340340
github.com/ipfs/go-peertaskqueue v0.8.3 h1:tBPpGJy+A92RqtRFq5amJn0Uuj8Pw8tXi0X3eHfHM8w=
341341
github.com/ipfs/go-peertaskqueue v0.8.3/go.mod h1:OqVync4kPOcXEGdj/LKvox9DCB5mkSBeXsPczCxLtYA=
342-
github.com/ipfs/go-test v0.3.0 h1:0Y4Uve3tp9HI+2lIJjfOliOrOgv/YpXg/l1y3P4DEYE=
343-
github.com/ipfs/go-test v0.3.0/go.mod h1:JK+U8pRpATZb7lsYNSJlCj3WYB3cFfWIbI6nWRM/GFk=
342+
github.com/ipfs/go-test v0.4.1 h1:n6uNSakIgpTQIRorqNg2O02aMIFDLQk2z4rBfrlD3Uw=
343+
github.com/ipfs/go-test v0.4.1/go.mod h1:QmvVBf9kClNtRuFow4DASq03eFvjKla4Fy/UAkeeLO8=
344344
github.com/ipfs/go-unixfsnode v1.10.5 h1:V34JV7fM90y+2ZUef7ToShjmwAZ8oo1yP7zrpWzC5L4=
345345
github.com/ipfs/go-unixfsnode v1.10.5/go.mod h1:u/9Ukl+XYpfKTMu+NXQqxbzAJVTwSCoyTYBGgE+JdSE=
346346
github.com/ipld/go-car/v2 v2.17.0 h1:zgjSxf/lQNYcQPX08cvb5rSdEY8sv5OOnQIsZhZMPx4=

fuse/readonly/ipfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func testMount(t *testing.T, root fs.InodeEmbedder) string {
5757

5858
func randObj(t *testing.T, nd *core.IpfsNode, size int64) (ipld.Node, []byte) {
5959
buf := make([]byte, size)
60-
_, err := io.ReadFull(random.NewRand(), buf)
60+
_, err := io.ReadFull(random.New(), buf)
6161
if err != nil {
6262
t.Fatal(err)
6363
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/hashicorp/go-version v1.9.0
2323
github.com/ipfs-shipyard/nopfs v0.0.14
2424
github.com/ipfs-shipyard/nopfs/ipfs v0.25.0
25-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09
25+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863
2626
github.com/ipfs/go-block-format v0.2.4
2727
github.com/ipfs/go-cid v0.6.2
2828
github.com/ipfs/go-cidutil v0.1.2
@@ -42,7 +42,7 @@ require (
4242
github.com/ipfs/go-log/v2 v2.9.2
4343
github.com/ipfs/go-metrics-interface v0.3.0
4444
github.com/ipfs/go-metrics-prometheus v0.1.0
45-
github.com/ipfs/go-test v0.3.0
45+
github.com/ipfs/go-test v0.4.1
4646
github.com/ipfs/go-unixfsnode v1.10.5
4747
github.com/ipld/go-car/v2 v2.17.0
4848
github.com/ipld/go-codec-dagpb v1.7.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.25.0 h1:OqNqsGZPX8zh3eFMO8Lf8EHRRnSGBMqcd
344344
github.com/ipfs-shipyard/nopfs/ipfs v0.25.0/go.mod h1:BxhUdtBgOXg1B+gAPEplkg/GpyTZY+kCMSfsJvvydqU=
345345
github.com/ipfs/bbloom v0.1.0 h1:nIWwfIE3AaG7RCDQIsrUonGCOTp7qSXzxH7ab/ss964=
346346
github.com/ipfs/bbloom v0.1.0/go.mod h1:lDy3A3i6ndgEW2z1CaRFvDi5/ZTzgM1IxA/pkL7Wgts=
347-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09 h1:jl4/IHR4IRb0QOVw6vFxUL4NRnetk1V42HIdipWu+aw=
348-
github.com/ipfs/boxo v0.41.1-0.20260707130650-177b35c8ef09/go.mod h1:mnR769LN1W7rDI6z1GBLmD15x4pvMdW0oWxik8j3y6g=
347+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863 h1:C3Xufr5x4qxdhlR3LKL6eKBMJQKpzeNBoGCniXv448I=
348+
github.com/ipfs/boxo v0.41.1-0.20260717051107-441032d6a863/go.mod h1:DLLtSR+2xJF3W5HRGPvL3H+y+MfBzdy1/IPlLwU0n1A=
349349
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
350350
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
351351
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
@@ -412,8 +412,8 @@ github.com/ipfs/go-metrics-prometheus v0.1.0 h1:bApWOHkrH3VTBHzTHrZSfq4n4weOZDzZ
412412
github.com/ipfs/go-metrics-prometheus v0.1.0/go.mod h1:2GtL525C/4yxtvSXpRJ4dnE45mCX9AS0XRa03vHx7G0=
413413
github.com/ipfs/go-peertaskqueue v0.8.3 h1:tBPpGJy+A92RqtRFq5amJn0Uuj8Pw8tXi0X3eHfHM8w=
414414
github.com/ipfs/go-peertaskqueue v0.8.3/go.mod h1:OqVync4kPOcXEGdj/LKvox9DCB5mkSBeXsPczCxLtYA=
415-
github.com/ipfs/go-test v0.3.0 h1:0Y4Uve3tp9HI+2lIJjfOliOrOgv/YpXg/l1y3P4DEYE=
416-
github.com/ipfs/go-test v0.3.0/go.mod h1:JK+U8pRpATZb7lsYNSJlCj3WYB3cFfWIbI6nWRM/GFk=
415+
github.com/ipfs/go-test v0.4.1 h1:n6uNSakIgpTQIRorqNg2O02aMIFDLQk2z4rBfrlD3Uw=
416+
github.com/ipfs/go-test v0.4.1/go.mod h1:QmvVBf9kClNtRuFow4DASq03eFvjKla4Fy/UAkeeLO8=
417417
github.com/ipfs/go-unixfsnode v1.10.5 h1:V34JV7fM90y+2ZUef7ToShjmwAZ8oo1yP7zrpWzC5L4=
418418
github.com/ipfs/go-unixfsnode v1.10.5/go.mod h1:u/9Ukl+XYpfKTMu+NXQqxbzAJVTwSCoyTYBGgE+JdSE=
419419
github.com/ipld/go-car/v2 v2.17.0 h1:zgjSxf/lQNYcQPX08cvb5rSdEY8sv5OOnQIsZhZMPx4=

test/bench/bench_cli_ipfs_add/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func compareResults() error {
4242

4343
func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
4444
var benchmarkError error
45+
seed := random.Uint64ToSeed(1)
46+
4547
results := testing.Benchmark(func(b *testing.B) {
4648
b.SetBytes(amount)
4749
for i := 0; i < b.N; i++ {
@@ -67,7 +69,6 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
6769
b.Fatal(err)
6870
}
6971

70-
const seed = 1
7172
f, err := os.CreateTemp("", "")
7273
if err != nil {
7374
benchmarkError = err
@@ -76,7 +77,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
7677
defer os.Remove(f.Name())
7778

7879
randReader := &io.LimitedReader{
79-
R: random.NewSeededRand(seed),
80+
R: random.NewSeeded(seed),
8081
N: amount,
8182
}
8283
if _, err := io.Copy(f, randReader); err != nil {

test/bench/offline_add/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func compareResults() error {
3434
}
3535

3636
func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
37+
seed := random.Uint64ToSeed(1)
3738
results := testing.Benchmark(func(b *testing.B) {
3839
b.SetBytes(amount)
3940
for i := 0; i < b.N; i++ {
@@ -51,15 +52,14 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
5152
b.Fatal(err)
5253
}
5354

54-
const seed = 1
5555
f, err := os.CreateTemp("", "")
5656
if err != nil {
5757
b.Fatal(err)
5858
}
5959
defer os.Remove(f.Name())
6060

6161
randReader := &io.LimitedReader{
62-
R: random.NewSeededRand(seed),
62+
R: random.NewSeeded(seed),
6363
N: amount,
6464
}
6565
_, err = io.Copy(f, randReader)

test/cli/pins_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ func TestPins(t *testing.T) {
223223
t.Parallel()
224224

225225
node := harness.NewT(t).NewNode().Init()
226-
cidAStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
227-
cidBStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
226+
rnd := random.New()
227+
cidAStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
228+
cidBStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
228229

229230
_ = node.IPFS("pin", "add", "--name", "testPin", cidAStr)
230231

@@ -251,9 +252,10 @@ func TestPins(t *testing.T) {
251252
t.Parallel()
252253

253254
node := harness.NewT(t).NewNode().Init()
254-
cidAStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
255-
cidBStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
256-
cidCStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
255+
rnd := random.New()
256+
cidAStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
257+
cidBStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
258+
cidCStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
257259

258260
outA := cidAStr + " recursive testPin"
259261
outB := cidBStr + " recursive testPin"
@@ -289,7 +291,8 @@ func TestPins(t *testing.T) {
289291
t.Parallel()
290292

291293
node := harness.NewT(t).NewNode().Init()
292-
cidStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
294+
rnd := random.New()
295+
cidStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
293296

294297
outBefore := cidStr + " recursive A"
295298
outAfter := cidStr + " recursive B"
@@ -310,8 +313,9 @@ func TestPins(t *testing.T) {
310313
t.Parallel()
311314

312315
node := harness.NewT(t).NewNode().Init()
313-
cidAStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
314-
cidBStr := node.IPFSAddStr(string(random.Bytes(1000)), "--pin=false")
316+
rnd := random.New()
317+
cidAStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
318+
cidBStr := node.IPFSAddStr(string(rnd.Bytes(1000)), "--pin=false")
315319

316320
_ = node.IPFS("pin", "add", "--name", "testPinJson", cidAStr)
317321

0 commit comments

Comments
 (0)