mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package remotedbserver
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
"github.com/ledgerwatch/erigon-lib/kv/memdb"
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
func TestKvServer_renew(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("fix me on win please")
|
|
}
|
|
|
|
require, ctx, db := require.New(t), context.Background(), memdb.NewTestDB(t)
|
|
require.NoError(db.Update(ctx, func(tx kv.RwTx) error {
|
|
wc, err := tx.RwCursorDupSort(kv.PlainState)
|
|
require.NoError(err)
|
|
require.NoError(wc.Append([]byte{1}, []byte{1}))
|
|
require.NoError(wc.Append([]byte{1}, []byte{2}))
|
|
require.NoError(wc.Append([]byte{2}, []byte{1}))
|
|
require.NoError(wc.Append([]byte{3}, []byte{1}))
|
|
return nil
|
|
}))
|
|
|
|
s := NewKvServer(ctx, db, nil, nil)
|
|
g, ctx := errgroup.WithContext(ctx)
|
|
testCase := func() error {
|
|
id, err := s.begin(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var c, c2 kv.Cursor
|
|
if err = s.with(id, func(tx kv.Tx) error {
|
|
c, err = tx.Cursor(kv.PlainState)
|
|
return err
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
k, v, err := c.First()
|
|
require.NoError(err)
|
|
require.Equal([]byte{1}, k)
|
|
require.Equal([]byte{1}, v)
|
|
|
|
if err = s.renew(ctx, id); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = s.with(id, func(tx kv.Tx) error {
|
|
c, err = tx.Cursor(kv.PlainState)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c2, err = tx.Cursor(kv.PlainState)
|
|
return err
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
k, v, err = c.Next()
|
|
require.NoError(err)
|
|
require.Equal([]byte{1}, k)
|
|
require.Equal([]byte{1}, v)
|
|
k, v, err = c2.Next()
|
|
require.NoError(err)
|
|
require.Equal([]byte{1}, k)
|
|
require.Equal([]byte{1}, v)
|
|
|
|
s.rollback(id)
|
|
return nil
|
|
}
|
|
for i := 0; i < 100; i++ {
|
|
g.Go(testCase)
|
|
}
|
|
require.NoError(g.Wait())
|
|
}
|