2019-03-18 10:55:06 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package monitor_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/memory"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMonitor(t *testing.T) {
|
2019-04-22 10:07:50 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
var freeBandwidth int64
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
storageNode.Storage2.Monitor.Loop.Pause()
|
|
|
|
|
|
|
|
info, err := storageNode.Kademlia.Service.FetchInfo(ctx, storageNode.Local().Node)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// assume that all storage nodes have the same initial values
|
|
|
|
freeBandwidth = info.Capacity.FreeBandwidth
|
|
|
|
}
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
expectedData := make([]byte, 100*memory.KiB)
|
|
|
|
_, err := rand.Read(expectedData)
|
2019-03-18 10:55:06 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "testbucket", "test/path", expectedData)
|
|
|
|
require.NoError(t, err)
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
nodeAssertions := 0
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
storageNode.Storage2.Monitor.Loop.TriggerWait()
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
info, err := storageNode.Kademlia.Service.FetchInfo(ctx, storageNode.Local().Node)
|
|
|
|
require.NoError(t, err)
|
2019-03-18 10:55:06 +00:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
stats, err := storageNode.Storage2.Inspector.Stats(ctx, &pb.StatsRequest{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
if stats.UsedSpace > 0 {
|
|
|
|
assert.Equal(t, freeBandwidth-stats.UsedBandwidth, info.Capacity.FreeBandwidth)
|
|
|
|
nodeAssertions++
|
|
|
|
}
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
2019-04-22 10:07:50 +01:00
|
|
|
assert.NotZero(t, nodeAssertions, "No storage node were verifed")
|
|
|
|
})
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|