fix: error during config when running benchmarks (#10495)
- Benchmarks were failing with error setting number of bits for ed25519 keys, which are the default now. - Update the random data generation package to remove a dependency. (cherry picked from commit 175aabdd85d2235e46bc163706dd7beb2c47ce05)
Andrew Gillis committed
Aug 28, 2024 at 09:21 UTC
f0d2c99d372f35bbbdf9ae344d697695b6e1a29b
5 files changed
+19
-16
go.mod
-1
@@ -44,7 +44,6 @@ require (
44
github.com/ipld/go-car/v2 v2.13.1
45
github.com/ipld/go-codec-dagpb v1.6.0
46
github.com/ipld/go-ipld-prime v0.21.0
47
- github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
47
github.com/jbenet/go-temp-err-catcher v0.1.0
48
github.com/jbenet/goprocess v0.1.4
49
github.com/julienschmidt/httprouter v1.3.0
go.sum
-2
@@ -446,8 +446,6 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
446
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
447
github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc=
448
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
449
-github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4=
450
-github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c/go.mod h1:sdx1xVM9UuLw1tXnhJWN3piypTUO3vCIHYmG15KE/dU=
449
github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk=
450
github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk=
451
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
test/bench/bench_cli_ipfs_add/main.go
+8
-3
@@ -3,6 +3,7 @@ package main
3
import (
4
"flag"
5
"fmt"
6
+ "io"
7
"log"
8
"os"
9
"os/exec"
@@ -11,8 +12,8 @@ import (
12
13
"github.com/ipfs/kubo/thirdparty/unit"
14
15
+ random "github.com/ipfs/go-test/random"
16
config "github.com/ipfs/kubo/config"
15
- random "github.com/jbenet/go-random"
17
)
18
19
var (
@@ -59,7 +60,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
60
}
61
}
62
62
- initCmd := exec.Command("ipfs", "init", "-b=2048")
63
+ initCmd := exec.Command("ipfs", "init")
64
setupCmd(initCmd)
65
if err := initCmd.Run(); err != nil {
66
benchmarkError = err
@@ -74,7 +75,11 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
75
}
76
defer os.Remove(f.Name())
77
77
- if err := random.WritePseudoRandomBytes(amount, f, seed); err != nil {
78
+ randReader := &io.LimitedReader{
79
+ R: random.NewSeededRand(seed),
80
+ N: amount,
81
+ }
82
+ if _, err := io.Copy(f, randReader); err != nil {
83
benchmarkError = err
84
b.Fatal(err)
85
}
test/bench/offline_add/main.go
+8
-3
@@ -2,6 +2,7 @@ package main
2
3
import (
4
"fmt"
5
+ "io"
6
"log"
7
"os"
8
"os/exec"
@@ -10,8 +11,8 @@ import (
11
12
"github.com/ipfs/kubo/thirdparty/unit"
13
14
+ random "github.com/ipfs/go-test/random"
15
config "github.com/ipfs/kubo/config"
14
- random "github.com/jbenet/go-random"
16
)
17
18
func main() {
@@ -44,7 +45,7 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
45
cmd.Env = env
46
}
47
47
- cmd := exec.Command("ipfs", "init", "-b=2048")
48
+ cmd := exec.Command("ipfs", "init")
49
setupCmd(cmd)
50
if err := cmd.Run(); err != nil {
51
b.Fatal(err)
@@ -57,7 +58,11 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) {
58
}
59
defer os.Remove(f.Name())
60
60
- err = random.WritePseudoRandomBytes(amount, f, seed)
61
+ randReader := &io.LimitedReader{
62
+ R: random.NewSeededRand(seed),
63
+ N: amount,
64
+ }
65
+ _, err = io.Copy(f, randReader)
66
if err != nil {
67
b.Fatal(err)
68
}
test/integration/addcat_test.go
+3
-7
@@ -14,11 +14,11 @@ import (
14
"github.com/ipfs/boxo/bootstrap"
15
"github.com/ipfs/boxo/files"
16
logging "github.com/ipfs/go-log"
17
+ "github.com/ipfs/go-test/random"
18
"github.com/ipfs/kubo/core"
19
"github.com/ipfs/kubo/core/coreapi"
20
mock "github.com/ipfs/kubo/core/mock"
21
"github.com/ipfs/kubo/thirdparty/unit"
21
- "github.com/jbenet/go-random"
22
testutil "github.com/libp2p/go-libp2p-testing/net"
23
"github.com/libp2p/go-libp2p/core/peer"
24
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
@@ -84,12 +84,8 @@ func AddCatPowers(conf testutil.LatencyConfig, megabytesMax int64) error {
84
}
85
86
func RandomBytes(n int64) []byte {
87
- var data bytes.Buffer
88
- err := random.WritePseudoRandomBytes(n, &data, kSeed)
89
- if err != nil {
90
- panic(err)
91
- }
92
- return data.Bytes()
87
+ random.SetSeed(kSeed)
88
+ return random.Bytes(int(n))
89
}
90
91
func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {