Skip to content

Commit

Permalink
meta: refactor migration test a bit
Browse files Browse the repository at this point in the history
Use complete DB reload to get closer to how node works in real life, it
usually opens an existing DB and any open/init code can affect the result.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Dec 12, 2024
1 parent 3e89a3d commit 562817d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/local_object_storage/metabase/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

objectconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
Expand Down Expand Up @@ -307,16 +308,20 @@ func TestMigrate2to3(t *testing.T) {
})
require.NoError(t, err)

// inhumeV2 stores data in the old format, but new DB has current version by default, force old version.
err = db.boltDB.Update(func(tx *bbolt.Tx) error {
err = updateVersion(tx, 2)
if err != nil {
return err
}

return migrateFrom2Version(db, tx)
return updateVersion(tx, 2)
})
require.NoError(t, err)

db.mode = mode.DegradedReadOnly // Force reload.
ok, err := db.Reload(WithPath(db.info.Path), WithEpochState(epochState{}))
require.True(t, ok)
require.NoError(t, err)

err = db.Init() // Migration happens here.
require.NoError(t, err)

err = db.boltDB.View(func(tx *bbolt.Tx) error {
return tx.Bucket(graveyardBucketName).ForEach(func(k, v []byte) error {
require.Len(t, v, addressKeySize+8)
Expand Down

0 comments on commit 562817d

Please sign in to comment.