Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use test module for random data generation #448

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/goreleaser-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.19.x"
go-version: "1.22.x"
- name: Check GoReleaser config
uses: goreleaser/goreleaser-action@v6
with:
Expand Down
6 changes: 3 additions & 3 deletions cardatatransfer/cardatatransfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/ipfs/go-graphsync/storeutil"
"github.com/ipfs/go-test/random"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/datamodel"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse"
"github.com/ipni/go-libipni/metadata"
"github.com/ipni/go-libipni/test"
"github.com/ipni/index-provider/cardatatransfer"
"github.com/ipni/index-provider/supplier"
"github.com/ipni/index-provider/testutil"
Expand All @@ -50,7 +50,7 @@ func TestCarDataTransfer(t *testing.T) {
require.NoError(t, err)
require.Len(t, roots2, 1)

missingCid := test.RandomCids(1)[0]
missingCid := random.Cids(1)[0]
missingContextID := []byte("notFound")

supplier := &fakeSupplier{blockstores: make(map[string]supplier.ClosableBlockstore)}
Expand All @@ -72,7 +72,7 @@ func TestCarDataTransfer(t *testing.T) {
pieceCID2 := pieceCIDFromContextID(t, contextID2)
missingPieceCID := pieceCIDFromContextID(t, missingContextID)

incorrectPieceCid := test.RandomCids(1)[0]
incorrectPieceCid := random.Cids(1)[0]

testCases := map[string]struct {
voucher datatransfer.TypedVoucher
Expand Down
6 changes: 3 additions & 3 deletions delegatedrouting/listener_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
leveldb "github.com/ipfs/go-ds-leveldb"
"github.com/ipni/go-libipni/test"
"github.com/ipfs/go-test/random"
drouting "github.com/ipni/index-provider/delegatedrouting"
"github.com/ipni/index-provider/engine"
mock_provider "github.com/ipni/index-provider/mock"
Expand All @@ -26,7 +26,7 @@ func TestHandleConcurrentRequests(t *testing.T) {
snapshotSize := 1000
concurrencyFactor := 10

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestShouldProcessMillionCIDsInThirtySeconds(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
ctx := context.Background()

engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
Expand Down
62 changes: 31 additions & 31 deletions delegatedrouting/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/ipfs/boxo/routing/http/server"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-test/random"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipni/go-libipni/metadata"
"github.com/ipni/go-libipni/test"
drouting "github.com/ipni/index-provider/delegatedrouting"
"github.com/ipni/index-provider/engine"
mock_provider "github.com/ipni/index-provider/mock"
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestDelegatedRoutingMultihashLister(t *testing.T) {
cids[newCid("test2")] = struct{}{}
cids[newCid("test3")] = struct{}{}

pID, _, _ := test.RandomIdentity()
pID, _, _ := random.Identity()

lister := &drouting.MultihashLister{
CidFetcher: func(contextID []byte) (map[cid.Cid]struct{}, error) {
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestProvideRoundtrip(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()

Expand Down Expand Up @@ -178,7 +178,7 @@ func TestProvideRoundtripWithRemove(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
ctx := context.Background()

engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestAdvertiseTwoChunksWithOneCidInEach(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestAdvertiseUsingAddrsFromParameters(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestProvideRegistersCidInDatastore(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestCidsAreOrderedByArrivalInExpiryQueue(t *testing.T) {
chunkSize := 1000
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestFullChunkAdvertisedAndRegisteredInDatastore(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestRemovedChunkIsRemovedFromIndexes(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestAdvertiseOneChunkWithTwoCidsInIt(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestDoNotReAdvertiseRepeatedCids(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestAdvertiseExpiredCidsIfProvidedAgain(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -547,7 +547,7 @@ func TestRemoveExpiredCidAndReadvertiseChunk(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -591,7 +591,7 @@ func TestExpireMultipleChunks(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -629,7 +629,7 @@ func TestDoNotReadvertiseChunkIfAllCidsExpired(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -667,7 +667,7 @@ func TestDoNotReadvertiseTheSameCids(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -698,7 +698,7 @@ func TestDoNotLoadRemovedChunksOnInitialisation(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -738,7 +738,7 @@ func TestMissingCidTimestampsBackfilledOnIntialisation(t *testing.T) {
chunkSize := 1
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -804,7 +804,7 @@ func TestSameCidNotDuplicatedInTheCurrentChunkIfProvidedTwice(t *testing.T) {
chunkSize := 2
snapshotSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -833,7 +833,7 @@ func TestShouldStoreSnapshotInDatastore(t *testing.T) {
ttl := time.Hour
chunkSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -874,7 +874,7 @@ func TestShouldNotStoreSnapshotInDatastore(t *testing.T) {
ttl := time.Hour
chunkSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -913,7 +913,7 @@ func TestShouldCleanUpTimestampMappingsFromDatastore(t *testing.T) {
ttl := time.Hour
chunkSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -959,7 +959,7 @@ func TestShouldCorrectlyMergeSnapshotAndCidTimestamps(t *testing.T) {
ttl := time.Hour
chunkSize := 1000

pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -1011,7 +1011,7 @@ func TestInitialiseFromDatastoreWithSnapshot(t *testing.T) {
}

func verifyInitialisationFromDatastore(t *testing.T, snapshotSize int, ttl time.Duration, chunkSize int) {
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
// total number of test cids to generate
// - has to be not even so that not all of the cids end up included into chunks
// - has to span multiple page sizes so that datastore is initialised in pages
Expand Down Expand Up @@ -1101,7 +1101,7 @@ func TestCleanUpExpiredCidsThatDontHaveChunk(t *testing.T) {
ttl := time.Second
chunkSize := 2
snapshotSize := 1000
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -1142,7 +1142,7 @@ func TestCidsWithoutChunkAreRegisteredInDsAndIndexes(t *testing.T) {
ttl := 1 * time.Hour
chunkSize := 2
snapshotSize := 1000
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down Expand Up @@ -1175,7 +1175,7 @@ func TestShouldSplitSnapshotIntoMultipleChunksAndReadThemBack(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
ctx := context.Background()

engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
Expand Down Expand Up @@ -1240,7 +1240,7 @@ func TestShouldCleanUpOldSnapshotChunksAfterStoringNewOnes(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
ctx := context.Background()

engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
Expand Down Expand Up @@ -1287,7 +1287,7 @@ func TestShouldRecogniseLegacySnapshot(t *testing.T) {

h, err := libp2p.New()
require.NoError(t, err)
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()
ctx := context.Background()

engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
Expand Down Expand Up @@ -1347,7 +1347,7 @@ func TestAdsFlush(t *testing.T) {
chunkSize := 2
snapshotSize := 1000
adFlusFreq := 100 * time.Millisecond
pID, priv, _ := test.RandomIdentity()
pID, priv, _ := random.Identity()

ctx := context.Background()
defer ctx.Done()
Expand Down
6 changes: 3 additions & 3 deletions engine/chunker/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/ipni/go-libipni/test"
"github.com/ipfs/go-test/random"
provider "github.com/ipni/index-provider"
"github.com/ipni/index-provider/engine/chunker"
"github.com/multiformats/go-multicodec"
Expand All @@ -25,7 +25,7 @@ func BenchmarkCachedChunker(b *testing.B) {

var mhis [][]multihash.Multihash
for i := 0; i < capacity; i++ {
mhis = append(mhis, test.RandomMultihashes(mhCount))
mhis = append(mhis, random.Multihashes(mhCount))
}

b.Run("ChainedEntryChunk/ChunkSize_1", benchmarkCachedChunker(ctx, byteSize, capacity, mhis, chunker.NewChainChunkerFunc(1)))
Expand Down Expand Up @@ -76,7 +76,7 @@ func BenchmarkRestoreCache_ChainChunker(b *testing.B) {
subject, err := chunker.NewCachedEntriesChunker(ctx, store, capacity, chunker.NewChainChunkerFunc(chunkSize), false)
require.NoError(b, err)
for i := 0; i < capacity; i++ {
mhi := test.RandomMultihashes(mhCount)
mhi := random.Multihashes(mhCount)
chunk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhi))
require.NoError(b, err)
require.NotNil(b, chunk)
Expand Down
Loading
Loading