Skip to content

Commit

Permalink
add intergration test
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Aug 11, 2023
1 parent 15b8b84 commit ee25882
Showing 1 changed file with 72 additions and 25 deletions.
97 changes: 72 additions & 25 deletions nodebuilder/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package nodebuilder

import (
"context"
"strconv"
"testing"

"github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"strconv"
"testing"
"time"

"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/celestia-app/pkg/wrapper"
Expand Down Expand Up @@ -68,30 +66,13 @@ func BenchmarkStore(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
b.Cleanup(cancel)

tmpDir := b.TempDir()
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
edsStore, err := eds.NewStore(tmpDir, ds)
require.NoError(b, err)
err = edsStore.Start(ctx)
require.NoError(b, err)

// BenchmarkStore/bench_read_128-10 14 78970661 ns/op (~70ms)
b.Run("bench put 128", func(b *testing.B) {
b.ResetTimer()
dir := b.TempDir()

err := Init(*DefaultConfig(node.Full), dir, node.Full)
require.NoError(b, err)

store, err := OpenStore(dir, nil)
require.NoError(b, err)
ds, err := store.Datastore()
require.NoError(b, err)
edsStore, err := eds.NewStore(dir, ds)
require.NoError(b, err)
err = edsStore.Start(ctx)
require.NoError(b, err)

store := newStore(b, ctx, dir)
size := 128
b.Run("enabled eds proof caching", func(b *testing.B) {
b.StopTimer()
Expand All @@ -111,7 +92,7 @@ func BenchmarkStore(b *testing.B) {
ctx := ipld.CtxWithProofsAdder(ctx, adder)

b.StartTimer()
err = edsStore.Put(ctx, dah.Hash(), eds)
err = store.edsStore.Put(ctx, dah.Hash(), eds)
b.StopTimer()
require.NoError(b, err)
}
Expand All @@ -126,10 +107,76 @@ func BenchmarkStore(b *testing.B) {
require.NoError(b, err)

b.StartTimer()
err = edsStore.Put(ctx, dah.Hash(), eds)
err = store.edsStore.Put(ctx, dah.Hash(), eds)
b.StopTimer()
require.NoError(b, err)
}
})
})
}

func TestStoreRestart(b *testing.T) {
const (
blocks = 5
size = 32
)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
b.Cleanup(cancel)

dir := b.TempDir()
err := Init(*DefaultConfig(node.Full), dir, node.Full)
require.NoError(b, err)

store := newStore(b, ctx, dir)

hashes := make([][]byte, blocks)
for i := range hashes {
edss := edstest.RandEDS(b, size)
require.NoError(b, err)
dah, err := da.NewDataAvailabilityHeader(edss)
require.NoError(b, err)
err = store.edsStore.Put(ctx, dah.Hash(), edss)
require.NoError(b, err)

// store hashes for read loop later
hashes[i] = dah.Hash()
}

// restart store
store.stop(b, ctx)
store = newStore(b, ctx, dir)

for _, h := range hashes {
edsReader, err := store.edsStore.GetCAR(ctx, h)
require.NoError(b, err)
odsReader, err := eds.ODSReader(edsReader)
require.NoError(b, err)
_, err = eds.ReadEDS(ctx, odsReader, h)
require.NoError(b, err)
}
}

type store struct {
s Store
edsStore *eds.Store
}

func newStore(t require.TestingT, ctx context.Context, dir string) store {

Check warning on line 164 in nodebuilder/store_test.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

context-as-argument: context.Context should be the first parameter of a function (revive)
s, err := OpenStore(dir, nil)
require.NoError(t, err)
ds, err := s.Datastore()
require.NoError(t, err)
edsStore, err := eds.NewStore(dir, ds)
require.NoError(t, err)
err = edsStore.Start(ctx)
require.NoError(t, err)
return store{
s: s,
edsStore: edsStore,
}
}

func (s *store) stop(t *testing.T, ctx context.Context) {

Check warning on line 179 in nodebuilder/store_test.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

context-as-argument: context.Context should be the first parameter of a function (revive)
require.NoError(t, s.edsStore.Stop(ctx))
require.NoError(t, s.s.Close())
}

0 comments on commit ee25882

Please sign in to comment.