2019-10-01 15:34:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2020-01-14 11:08:38 +00:00
|
|
|
package gracefulexit_test
|
2019-10-01 15:34:03 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-10-01 15:34:03 +01:00
|
|
|
"storj.io/storj/storagenode"
|
|
|
|
"storj.io/storj/storagenode/satellites"
|
|
|
|
"storj.io/storj/storagenode/storagenodedb/storagenodedbtest"
|
|
|
|
)
|
|
|
|
|
2020-01-14 11:08:38 +00:00
|
|
|
// TestDB tests the graceful exit database calls
|
|
|
|
func TestDB(t *testing.T) {
|
2020-01-20 14:56:12 +00:00
|
|
|
storagenodedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db storagenode.DB) {
|
2019-10-01 15:34:03 +01:00
|
|
|
for i := 0; i <= 3; i++ {
|
|
|
|
nodeID := testrand.NodeID()
|
|
|
|
start := time.Now()
|
2019-10-28 17:59:45 +00:00
|
|
|
|
|
|
|
_, err := db.Satellites().GetSatellite(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-01 15:34:03 +01:00
|
|
|
require.NoError(t, db.Satellites().InitiateGracefulExit(ctx, nodeID, start, 5000))
|
|
|
|
exits, err := db.Satellites().ListGracefulExits(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(exits), i+1)
|
|
|
|
require.Equal(t, exits[i].BytesDeleted, int64(0))
|
|
|
|
require.Equal(t, exits[i].CompletionReceipt, []byte(nil))
|
2020-03-10 22:05:01 +00:00
|
|
|
require.True(t, exits[i].InitiatedAt.Equal(start))
|
2019-10-01 15:34:03 +01:00
|
|
|
require.Nil(t, exits[i].FinishedAt)
|
|
|
|
require.Equal(t, exits[i].SatelliteID, nodeID)
|
|
|
|
require.Equal(t, exits[i].StartingDiskUsage, int64(5000))
|
|
|
|
|
|
|
|
require.NoError(t, db.Satellites().UpdateGracefulExit(ctx, nodeID, 1000))
|
|
|
|
require.NoError(t, db.Satellites().UpdateGracefulExit(ctx, nodeID, 1000))
|
|
|
|
require.NoError(t, db.Satellites().UpdateGracefulExit(ctx, nodeID, 1000))
|
|
|
|
|
|
|
|
exits, err = db.Satellites().ListGracefulExits(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(exits), i+1)
|
|
|
|
require.Equal(t, exits[i].BytesDeleted, int64(3000))
|
|
|
|
require.Equal(t, exits[i].CompletionReceipt, []byte(nil))
|
2020-03-10 22:05:01 +00:00
|
|
|
require.True(t, exits[i].InitiatedAt.Equal(start))
|
2019-10-01 15:34:03 +01:00
|
|
|
require.Nil(t, exits[i].FinishedAt)
|
|
|
|
require.Equal(t, exits[i].SatelliteID, nodeID)
|
|
|
|
require.Equal(t, exits[i].StartingDiskUsage, int64(5000))
|
|
|
|
|
|
|
|
stop := time.Now()
|
|
|
|
require.NoError(t, db.Satellites().CompleteGracefulExit(ctx, nodeID, stop, satellites.ExitSucceeded, []byte{0, 0, 0}))
|
|
|
|
exits, err = db.Satellites().ListGracefulExits(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(exits), i+1)
|
|
|
|
require.Equal(t, exits[i].BytesDeleted, int64(3000))
|
|
|
|
require.Equal(t, exits[i].CompletionReceipt, []byte{0, 0, 0})
|
2020-03-10 22:05:01 +00:00
|
|
|
require.True(t, exits[i].InitiatedAt.Equal(start))
|
|
|
|
require.True(t, exits[i].FinishedAt.Equal(stop))
|
2019-10-01 15:34:03 +01:00
|
|
|
require.Equal(t, exits[i].SatelliteID, nodeID)
|
|
|
|
require.Equal(t, exits[i].StartingDiskUsage, int64(5000))
|
2019-10-28 17:59:45 +00:00
|
|
|
|
|
|
|
satellite, err := db.Satellites().GetSatellite(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, nodeID, satellite.SatelliteID)
|
|
|
|
require.False(t, satellite.AddedAt.IsZero())
|
|
|
|
require.EqualValues(t, 3, satellite.Status)
|
2019-10-01 15:34:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|