Skip to content

Commit

Permalink
Use ipfs/go-test
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Jun 28, 2024
1 parent 3d545af commit 8dc0c6c
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 101 deletions.
34 changes: 17 additions & 17 deletions cache/radixcache/radixcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"runtime"
"testing"

"github.com/ipfs/go-test/random"
"github.com/ipni/go-indexer-core"
"github.com/ipni/go-indexer-core/store/test"
"github.com/libp2p/go-libp2p/core/peer"
)

Expand All @@ -28,7 +28,7 @@ func init() {

func TestPutGetRemove(t *testing.T) {
s := New(1000000)
mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

provID, err := peer.Decode(peerID)
if err != nil {
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestPutGetRemove(t *testing.T) {
func TestRotate(t *testing.T) {
const maxSize = 10

mhs := test.RandomMultihashes(2)
mhs := random.Multihashes(2)

value1 := indexer.Value{
ProviderID: provID,
Expand All @@ -205,7 +205,7 @@ func TestRotate(t *testing.T) {
}

s := New(maxSize * 2)
mhs = test.RandomMultihashes(maxSize + 5)
mhs = random.Multihashes(maxSize + 5)

s.Put(value1, mhs...)
stats := s.Stats()
Expand All @@ -223,7 +223,7 @@ func TestRotate(t *testing.T) {
t.Error("Error finding a multihash from new cache")
}

mhs2 := test.RandomMultihashes(maxSize)
mhs2 := random.Multihashes(maxSize)

if s.Put(value2, mhs2...) != len(mhs2) {
t.Fatal("did not put batch of multihashes")
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestRotate(t *testing.T) {
func TestUnboundedGrowth(t *testing.T) {
const maxSize = 4
s := New(maxSize)
mhs := test.RandomMultihashes(11)
mhs := random.Multihashes(11)

mhash := mhs[0]
mhs = mhs[1:]
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestRemoveProvider(t *testing.T) {
MetadataBytes: []byte("ctx3-metadata"),
}

mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

batch1 := mhs[:5]
batch2 := mhs[5:10]
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestRemoveProviderContext(t *testing.T) {
MetadataBytes: []byte("ctx3-metadata"),
}

mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

batch1 := mhs[:5]
batch2 := mhs[5:10]
Expand Down Expand Up @@ -507,7 +507,7 @@ func TestRemoveProviderContext(t *testing.T) {
func TestMemoryUse(t *testing.T) {
skipUnlessMemUse(t)

mhs := test.RandomMultihashes(1)
mhs := random.Multihashes(1)

ctxID := []byte("test-ctx-1")
value := indexer.Value{
Expand All @@ -522,7 +522,7 @@ func TestMemoryUse(t *testing.T) {
t.Run(fmt.Sprintf("MemoryUse %d multihashes", count*1024), func(t *testing.T) {
s := New(1024 * count)
for i := 0; i < count; i++ {
mhs = test.RandomMultihashes(1024)
mhs = random.Multihashes(1024)
s.Put(value, mhs...)
}
mhs = nil
Expand All @@ -546,7 +546,7 @@ func TestMemoryUse(t *testing.T) {
func TestMemSingleVsMany(t *testing.T) {
skipUnlessMemUse(t)

mhs := test.RandomMultihashes(1)
mhs := random.Multihashes(1)

value := indexer.Value{
ProviderID: provID,
Expand All @@ -557,7 +557,7 @@ func TestMemSingleVsMany(t *testing.T) {
t.Run(fmt.Sprintf("Put %d Single multihashes", 1024*1024), func(t *testing.T) {
s := New(1024 * 1024)
for i := 0; i < 1024; i++ {
mhs = test.RandomMultihashes(1024)
mhs = random.Multihashes(1024)
for j := range mhs {
s.Put(value, mhs[j])
}
Expand All @@ -571,7 +571,7 @@ func TestMemSingleVsMany(t *testing.T) {
t.Run(fmt.Sprintf("Put %d multihashes in groups of 1024", 1024*1024), func(t *testing.T) {
s := New(1024 * 1024)
for i := 0; i < 1024; i++ {
mhs = test.RandomMultihashes(1024)
mhs = random.Multihashes(1024)
s.Put(value, mhs...)
}
runtime.GC()
Expand All @@ -582,14 +582,14 @@ func TestMemSingleVsMany(t *testing.T) {
}

func BenchmarkPut(b *testing.B) {
mhs := test.RandomMultihashes(1)
mhs := random.Multihashes(1)
value := indexer.Value{
ProviderID: provID,
ContextID: ctxID,
MetadataBytes: []byte(mhs[0]),
}

mhs = test.RandomMultihashes(10240)
mhs = random.Multihashes(10240)

b.Run("Put single", func(b *testing.B) {
s := New(8192)
Expand Down Expand Up @@ -625,15 +625,15 @@ func BenchmarkPut(b *testing.B) {
}

func BenchmarkGet(b *testing.B) {
mhs := test.RandomMultihashes(1)
mhs := random.Multihashes(1)
value := indexer.Value{
ProviderID: provID,
ContextID: ctxID,
MetadataBytes: []byte(mhs[0]),
}

s := New(8192)
mhs = test.RandomMultihashes(4096)
mhs = random.Multihashes(4096)
s.Put(value, mhs...)

b.Run("Get single", func(b *testing.B) {
Expand Down
16 changes: 8 additions & 8 deletions engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"testing"

"github.com/ipfs/go-test/random"
"github.com/ipni/go-indexer-core"
"github.com/ipni/go-indexer-core/cache"
"github.com/ipni/go-indexer-core/cache/radixcache"
"github.com/ipni/go-indexer-core/store/memory"
"github.com/ipni/go-indexer-core/store/pebble"
"github.com/ipni/go-indexer-core/store/test"
"github.com/ipni/go-indexer-core/store/vsinfo"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestPassthrough(t *testing.T) {
t.Fatal(err)
}

mhs := test.RandomMultihashes(5)
mhs := random.Multihashes(5)

value1 := indexer.Value{
ProviderID: p,
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestRemoveProvider(t *testing.T) {
MetadataBytes: []byte("ctx3-metadata"),
}

mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

batch1 := mhs[:5]
batch2 := mhs[5:10]
Expand Down Expand Up @@ -298,7 +298,7 @@ func TestCacheOnPut(t *testing.T) {
t.Fatal(err)
}

mhs := test.RandomMultihashes(3)
mhs := random.Multihashes(3)

value1 := indexer.Value{
ProviderID: p,
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestRemoveProviderContext(t *testing.T) {
MetadataBytes: []byte("ctx3-metadata"),
}

mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

batch1 := mhs[:5]
batch2 := mhs[5:10]
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestMultiCodec(t *testing.T) {
t.Fatal(err)
}

mhs := test.RandomMultihashes(5)
mhs := random.Multihashes(5)

value1 := indexer.Value{
ProviderID: p,
Expand Down Expand Up @@ -653,7 +653,7 @@ func e2e(t *testing.T, eng *Engine) {
t.Fatal(err)
}

mhs := test.RandomMultihashes(15)
mhs := random.Multihashes(15)

value1 := indexer.Value{
ProviderID: p,
Expand Down Expand Up @@ -780,7 +780,7 @@ func SizeTest(t *testing.T) {
t.Fatal(err)
}

mhs := test.RandomMultihashes(151)
mhs := random.Multihashes(151)

value := indexer.Value{
ProviderID: p,
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ require (
github.com/gammazero/radixtree v0.3.1
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipni/go-libipni v0.5.20
github.com/ipfs/go-test v0.0.2
github.com/ipni/go-libipni v0.6.8
github.com/libp2p/go-libp2p v0.35.1
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multihash v0.2.3
Expand All @@ -33,6 +34,8 @@ require (
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/ipfs/go-block-format v0.1.2 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand Down
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,20 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/ipfs/go-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=
github.com/ipfs/go-block-format v0.1.2/go.mod h1:mACVcrxarQKstUU3Yf/RdwbC4DzPV6++rO2a3d+a/KE=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk=
github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8=
github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ=
github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY=
github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI=
github.com/ipfs/go-test v0.0.2 h1:Wdxl4bKEdjEM8SLiulXMHlAQwHYOhX3CSBoUoEvncmM=
github.com/ipfs/go-test v0.0.2/go.mod h1:qhIM1EluEfElKKM6fnWxGn822/z9knUGM1+I/OAQNKI=
github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E=
github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ=
github.com/ipni/go-libipni v0.5.20 h1:vJ63XZMX8ezvjv2n/4xNTxguA/E32ZViDBdl9Z9I+G4=
github.com/ipni/go-libipni v0.5.20/go.mod h1:L0GKEDGtQ0hVr+q7NBOAevqh4Q8QwB1stsNBtBUax/A=
github.com/ipni/go-libipni v0.6.8 h1:bwyu7g+1jwgCptabQ6It2VtFucFJIsOckzQNBBObHoE=
github.com/ipni/go-libipni v0.6.8/go.mod h1:yXjq2JgqPMcubWpJie3OjyG0HNIoRdbmqxQMx+gF4TM=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
Expand All @@ -102,8 +108,11 @@ github.com/libp2p/go-libp2p v0.35.1/go.mod h1:Dnkgba5hsfSv5dvvXC8nfqk44hH0gIKKno
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE=
Expand All @@ -116,8 +125,10 @@ github.com/multiformats/go-multibase v0.2.0 h1:isdYCVLvksgWlMW9OZRYJEa9pZETFivnc
github.com/multiformats/go-multibase v0.2.0/go.mod h1:bFBZX4lKCA/2lyOFSAoKH5SS6oPyjtnzK/XTFDPkNuk=
github.com/multiformats/go-multicodec v0.9.0 h1:pb/dlPnzee/Sxv/j4PmkDRxCOi3hXTz3IbPKOXWJkmg=
github.com/multiformats/go-multicodec v0.9.0/go.mod h1:L3QTQvMIaVBkXOXXtVmYE+LI16i14xuaojr/H7Ai54k=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
Expand Down Expand Up @@ -170,6 +181,7 @@ go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
Expand Down
Loading

0 comments on commit 8dc0c6c

Please sign in to comment.