storagenode/storagenodedb/storagenodedbtest: pass ctx as an argument

Change-Id: I10b0a8ef3a7d5001e7d361f1873ad5987af1f9c2
This commit is contained in:
Egon Elbre 2020-01-20 16:56:12 +02:00
parent f3b4bf2b7c
commit 21f53e38da
14 changed files with 34 additions and 130 deletions

View File

@ -56,10 +56,7 @@ var (
)
func TestBandwidthDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
bandwidthdb := db.Bandwidth()
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion()).ID
@ -133,10 +130,7 @@ func TestBandwidthDB(t *testing.T) {
}
func TestEgressSummary(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
bandwidthdb := db.Bandwidth()
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion()).ID
@ -204,10 +198,7 @@ func TestEgressSummary(t *testing.T) {
}
func TestIngressSummary(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
bandwidthdb := db.Bandwidth()
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion()).ID
@ -275,10 +266,7 @@ func TestIngressSummary(t *testing.T) {
}
func TestEmptyBandwidthDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
bandwidthdb := db.Bandwidth()
now := time.Now()
@ -316,10 +304,7 @@ func TestEmptyBandwidthDB(t *testing.T) {
}
func TestBandwidthDailyRollups(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
const (
numSatellites = 5
days = 30
@ -449,10 +434,7 @@ func TestBandwidthDailyRollups(t *testing.T) {
}
func TestCachedBandwidthMonthRollover(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
bandwidthdb := db.Bandwidth()
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion()).ID
@ -487,10 +469,7 @@ func TestCachedBandwidthMonthRollover(t *testing.T) {
}
func TestBandwidthRollup(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
err := db.CreateTables(ctx)
if err != nil {
t.Fatal(err)
@ -593,10 +572,7 @@ func TestBandwidthRollup(t *testing.T) {
}
func TestDB_Trivial(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
{ // Ensure Add works at all
err := db.Bandwidth().Add(ctx, testrand.NodeID(), pb.PieceAction_GET, 0, time.Now())
require.NoError(t, err)

View File

@ -18,10 +18,7 @@ import (
// TestDB tests the graceful exit database calls
func TestDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
for i := 0; i <= 3; i++ {
nodeID := testrand.NodeID()
start := time.Now()

View File

@ -19,10 +19,7 @@ import (
)
func TestNotificationsDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
notificationsdb := db.Notifications()
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion()).ID
@ -129,10 +126,7 @@ func TestNotificationsDB(t *testing.T) {
}
func TestEmptyNotificationsDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
notificationsdb := db.Notifications()
notificationCursor := notifications.Cursor{

View File

@ -22,10 +22,7 @@ import (
)
func TestDB(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
ordersdb := db.Orders()
storagenode := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion())
@ -189,10 +186,7 @@ func TestDB(t *testing.T) {
}
func TestDB_Trivial(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
satelliteID, serial := testrand.NodeID(), testrand.SerialNumber()
{ // Ensure Enqueue works at all

View File

@ -25,10 +25,7 @@ import (
)
func TestDBInit(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
spaceUsedDB := db.PieceSpaceUsedDB()
total, err := spaceUsedDB.GetPieceTotal(ctx)
require.NoError(t, err)
@ -68,10 +65,7 @@ func TestDBInit(t *testing.T) {
})
}
func TestCacheInit(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
spaceUsedDB := db.PieceSpaceUsedDB()
err := spaceUsedDB.Init(ctx)
require.NoError(t, err)
@ -140,10 +134,7 @@ func TestCacheInit(t *testing.T) {
}
func TestPersistCacheTotals(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
// The database should start out with 0 for all totals
var expectedPieces int64
spaceUsedDB := db.PieceSpaceUsedDB()
@ -321,10 +312,7 @@ func TestRecalculateCacheMissed(t *testing.T) {
}
func TestCacheCreateDeleteAndTrash(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
cache := pieces.NewBlobsUsageCache(db.Pieces())
pieceContent := []byte("stuff")
satelliteID := testrand.NodeID()

View File

@ -23,10 +23,7 @@ import (
)
func TestV0PieceInfo(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
pieceinfos := db.V0PieceInfo().(pieces.V0PieceInfoDBForTest)
satellite0 := testidentity.MustPregeneratedSignedIdentity(0, storj.LatestIDVersion())
@ -172,10 +169,7 @@ func TestV0PieceInfo(t *testing.T) {
}
func TestPieceinfo_Trivial(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
pieceinfos := db.V0PieceInfo().(pieces.V0PieceInfoDBForTest)
satelliteID, pieceID := testrand.NodeID(), testrand.PieceID()

View File

@ -19,10 +19,7 @@ import (
func TestPieceExpirationDB(t *testing.T) {
// test GetExpired, SetExpiration, DeleteExpiration, DeleteFailed
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
expireDB := db.PieceExpirationDB()
satelliteID := testrand.NodeID()

View File

@ -309,10 +309,7 @@ func TestTrashAndRestore(t *testing.T) {
},
}
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
dir, err := filestore.NewDir(ctx.Dir("store"))
require.NoError(t, err)
@ -517,12 +514,9 @@ func verifyPieceData(ctx context.Context, t testing.TB, store *pieces.Store, sat
}
func TestPieceVersionMigrate(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
const pieceSize = 1024
ctx := testcontext.New(t)
defer ctx.Cleanup()
var (
data = testrand.Bytes(pieceSize)
satelliteID = testrand.NodeID()
@ -691,10 +685,7 @@ func TestMultipleStorageFormatVersions(t *testing.T) {
}
func TestGetExpired(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
v0PieceInfo, ok := db.V0PieceInfo().(pieces.V0PieceInfoDBForTest)
require.True(t, ok, "V0PieceInfoDB can not satisfy V0PieceInfoDBForTest")
expirationInfo := db.PieceExpirationDB()
@ -761,10 +752,7 @@ func TestGetExpired(t *testing.T) {
}
func TestOverwriteV0WithV1(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
v0PieceInfo, ok := db.V0PieceInfo().(pieces.V0PieceInfoDBForTest)
require.True(t, ok, "V0PieceInfoDB can not satisfy V0PieceInfoDBForTest")
expirationInfo := db.PieceExpirationDB()

View File

@ -20,10 +20,7 @@ import (
)
func TestUsedSerials(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
usedSerials := db.UsedSerials()
node0 := testidentity.MustPregeneratedIdentity(0, storj.LatestIDVersion())
@ -103,10 +100,7 @@ func TestUsedSerials(t *testing.T) {
}
func TestUsedSerials_Trivial(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
satelliteID, serial := testrand.NodeID(), testrand.SerialNumber()
{ // Ensure Add works at all

View File

@ -18,10 +18,7 @@ import (
)
func TestReputationDBGetInsert(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
timestamp := time.Now().UTC()
reputationDB := db.Reputation()
@ -65,10 +62,7 @@ func TestReputationDBGetInsert(t *testing.T) {
}
func TestReputationDBGetAll(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
reputationDB := db.Reputation()
var stats []reputation.Stats

View File

@ -30,10 +30,7 @@ import (
)
func TestRetainPieces(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
store := pieces.NewStore(zaptest.NewLogger(t), db.Pieces(), db.V0PieceInfo(), db.PieceExpirationDB(), db.PieceSpaceUsedDB())
testStore := pieces.StoreForTest{Store: store}

View File

@ -25,7 +25,7 @@ func init() {
// Run method will iterate over all supported databases. Will establish
// connection and will create tables for each DB.
func Run(t *testing.T, test func(t *testing.T, db storagenode.DB)) {
func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db storagenode.DB)) {
t.Run("Sqlite", func(t *testing.T) {
t.Parallel()
ctx := testcontext.New(t)
@ -53,6 +53,6 @@ func Run(t *testing.T, test func(t *testing.T, db storagenode.DB)) {
t.Fatal(err)
}
test(t, db)
test(ctx, t, db)
})
}

View File

@ -29,10 +29,7 @@ import (
)
func TestDatabase(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
// Ensure that database implementation handles context cancellation.
canceledCtx, cancel := context.WithCancel(ctx)
cancel()

View File

@ -52,10 +52,7 @@ func TestStorageUsage(t *testing.T) {
dailyStampsTotals[stamp.IntervalStart.UTC()] += stamp.AtRestTotal
}
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
storageUsageDB := db.StorageUsage()
t.Run("test store", func(t *testing.T) {
@ -101,10 +98,7 @@ func TestStorageUsage(t *testing.T) {
}
func TestEmptyStorageUsage(t *testing.T) {
storagenodedbtest.Run(t, func(t *testing.T, db storagenode.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
var emptySummary float64
now := time.Now()