storj/storagenode/preflight/db_test.go
Moby von Briesen dc57640d9c storagenode/piecestore: switch usedserials db for in-memory usedserials store
Part 2 of moving usedserials in memory
* Drop usedserials table in storagenodedb
* Use in-memory usedserials store in place of db for order limit
verification
* Update order limit grace period to be only one hour - this means
uplinks must send their order limits to storagenodes within an hour of
receiving them

Change-Id: I37a0e1d2ca6cb80854a3ef495af2d1d1f92e9f03
2020-05-28 12:52:52 -04:00

74 lines
2.4 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package preflight_test
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/storagenode"
"storj.io/storj/storagenode/storagenodedb"
"storj.io/storj/storagenode/storagenodedb/storagenodedbtest"
)
func TestPreflightSchema(t *testing.T) {
// no change should not cause a preflight error
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
err := db.Preflight(ctx)
require.NoError(t, err)
})
// adding something to the schema should cause a preflight error
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
err := db.Preflight(ctx)
require.NoError(t, err)
// add index to used serials db
rawDBs := db.(*storagenodedb.DB).RawDatabases()
satellitesDB := rawDBs[storagenodedb.SatellitesDBName]
_, err = satellitesDB.GetDB().Exec(ctx, "CREATE INDEX a_new_index ON satellites(status)")
require.NoError(t, err)
// expect error from preflight check for addition
err = db.Preflight(ctx)
require.Error(t, err)
require.True(t, storagenodedb.ErrPreflight.Has(err))
})
// removing something from the schema should cause a preflight error
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
err := db.Preflight(ctx)
require.NoError(t, err)
// remove index from used serials db
rawDBs := db.(*storagenodedb.DB).RawDatabases()
bandwidthDB := rawDBs[storagenodedb.BandwidthDBName]
_, err = bandwidthDB.GetDB().Exec(ctx, "DROP INDEX idx_bandwidth_usage_created;")
require.NoError(t, err)
// expect error from preflight check for removal
err = db.Preflight(ctx)
require.Error(t, err)
require.True(t, storagenodedb.ErrPreflight.Has(err))
})
// having a test table should not cause the preflight check to fail
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
err := db.Preflight(ctx)
require.NoError(t, err)
// add test_table to used serials db
rawDBs := db.(*storagenodedb.DB).RawDatabases()
bandwidthDB := rawDBs[storagenodedb.BandwidthDBName]
_, err = bandwidthDB.GetDB().Exec(ctx, "CREATE TABLE test_table(id int NOT NULL, name varchar(30), PRIMARY KEY (id));")
require.NoError(t, err)
// expect no error from preflight check with added test_table
err = db.Preflight(ctx)
require.NoError(t, err)
})
}