storj/satellite/downtime/service_test.go
Cameron Ayer 3e70a893dd storagenode/{piecestore, contact}: report capacity to satellites if below specific threshold
Curently, storage nodes only report their capacity to satellites
once per hour. If a node fills up, it will fail all uploads until
the next contact cycle begins. With these changes, at the end of an
upload we check whether the MinimumDiskSpace threshold has been
passed. If so, trigger the monitor chore to update the node's
capacity, then trigger the contact chore to report the new
capacity to the satellites

Change-Id: Ie6aadaade1e2c12c87e03f8ff9059a50121380a0
2020-02-18 15:42:48 -05:00

64 lines
2.3 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package downtime_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
)
func TestCheckNodeAvailability(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
node := planet.StorageNodes[0]
nodeDossier := planet.StorageNodes[0].Local()
satellite := planet.Satellites[0]
require.NoError(t, node.Contact.Chore.Pause(ctx))
satellite.Audit.Chore.Loop.Pause()
// test that last success and failure checks are before now
beforeSuccessfulCheck := time.Now()
dossier, err := satellite.Overlay.Service.Get(ctx, node.ID())
require.NoError(t, err)
require.True(t, dossier.Reputation.LastContactSuccess.Before(beforeSuccessfulCheck))
require.True(t, dossier.Reputation.LastContactFailure.Before(beforeSuccessfulCheck))
success, err := satellite.DowntimeTracking.Service.CheckAndUpdateNodeAvailability(ctx, nodeDossier.Id, nodeDossier.Address.GetAddress())
require.NoError(t, err)
require.True(t, success)
lastFailure := dossier.Reputation.LastContactFailure
// now test that CheckAndUpdateNodeAvailability updated with a success, and the last contact failure is the same.
dossier, err = satellite.Overlay.Service.Get(ctx, node.ID())
require.NoError(t, err)
require.True(t, dossier.Reputation.LastContactSuccess.After(beforeSuccessfulCheck))
require.True(t, dossier.Reputation.LastContactFailure.Equal(lastFailure))
lastSuccess := dossier.Reputation.LastContactSuccess
// shutdown the node
err = node.Server.Close()
require.NoError(t, err)
// now test that CheckAndUpdateNodeAvailability updated with a failure, and the last contact success is the same
beforeFailedCheck := time.Now()
success, err = satellite.DowntimeTracking.Service.CheckAndUpdateNodeAvailability(ctx, nodeDossier.Id, nodeDossier.Address.GetAddress())
require.NoError(t, err)
require.False(t, success)
dossier, err = satellite.Overlay.Service.Get(ctx, node.ID())
require.NoError(t, err)
require.True(t, dossier.Reputation.LastContactFailure.After(beforeFailedCheck))
require.True(t, dossier.Reputation.LastContactSuccess.Equal(lastSuccess))
})
}