Skip to content

Commit

Permalink
fix syncer test
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Aug 1, 2024
1 parent cdb5de9 commit 0c93588
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestSync_InvalidSyncTarget(t *testing.T) {
head := suite.Head()

// create a local store which is initialised at genesis height
localStore := newTestStore(t, ctx, head)
localStore := newTestStore(t, ctx, head, store.WithWriteBatchSize(10))
// create a peer which is already on height 100
remoteStore := headertest.NewStore(t, suite, 100)

Expand Down Expand Up @@ -347,7 +347,14 @@ func TestSync_InvalidSyncTarget(t *testing.T) {
// ensure syncer could only sync up to one header below the bad sync target
h, err := localStore.Head(ctx)
require.NoError(t, err)
require.Equal(t, maliciousHeader.Height()-1, h.Height())

// we need to wait for a flush
assert.Eventually(t, func() bool {
h, err = localStore.Head(ctx)
require.NoError(t, err)

return maliciousHeader.Height()-1 == h.Height()
}, time.Second, 100*time.Millisecond)

// manually change bad sync target to a good header in remote peer
// store so it can re-serve it to syncer once it re-requests the height
Expand Down Expand Up @@ -400,7 +407,7 @@ func (d *delayedGetter[H]) GetRangeByHeight(ctx context.Context, from H, to uint
}

// newTestStore creates initialized and started in memory header Store which is useful for testing.
func newTestStore(tb testing.TB, ctx context.Context, head *headertest.DummyHeader) header.Store[*headertest.DummyHeader] {
func newTestStore(tb testing.TB, ctx context.Context, head *headertest.DummyHeader, opts ...store.Option) header.Store[*headertest.DummyHeader] {
ds := sync.MutexWrap(datastore.NewMapDatastore())
return store.NewTestStore(tb, ctx, ds, head)
return store.NewTestStore(tb, ctx, ds, head, opts...)
}

0 comments on commit 0c93588

Please sign in to comment.