2019-09-06 17:14:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-10-28 14:04:31 +00:00
|
|
|
"time"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-09-27 16:47:57 +01:00
|
|
|
"golang.org/x/sync/errgroup"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/testcontext"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-09-06 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoragenodeContactEndpoint(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
pingStats := planet.StorageNodes[0].Contact.PingStats
|
|
|
|
|
2020-05-19 16:49:13 +01:00
|
|
|
conn, err := planet.Satellites[0].Dialer.DialNodeURL(ctx, planet.StorageNodes[0].NodeURL())
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
2020-03-25 12:15:27 +00:00
|
|
|
resp, err := pb.NewDRPCContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 19:31:39 +01:00
|
|
|
firstPing := pingStats.WhenLastPinged()
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2020-10-13 13:47:55 +01:00
|
|
|
time.Sleep(time.Second) // HACKFIX: windows has large time granularity
|
2019-10-28 14:04:31 +00:00
|
|
|
|
2020-03-25 12:15:27 +00:00
|
|
|
resp, err = pb.NewDRPCContactClient(conn).PingNode(ctx, &pb.ContactPingRequest{})
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NotNil(t, resp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-10-03 19:31:39 +01:00
|
|
|
secondPing := pingStats.WhenLastPinged()
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
require.True(t, secondPing.After(firstPing))
|
|
|
|
})
|
|
|
|
}
|
2019-09-13 12:53:48 +01:00
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
func TestNodeInfoUpdated(t *testing.T) {
|
2019-09-13 12:53:48 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
|
2020-02-19 18:32:53 +00:00
|
|
|
node.Contact.Chore.Pause(ctx)
|
2019-09-13 12:53:48 +01:00
|
|
|
oldInfo, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
oldCapacity := oldInfo.Capacity
|
|
|
|
|
|
|
|
newCapacity := pb.NodeCapacity{
|
2020-02-12 21:19:42 +00:00
|
|
|
FreeDisk: 0,
|
2019-09-13 12:53:48 +01:00
|
|
|
}
|
|
|
|
require.NotEqual(t, oldCapacity, newCapacity)
|
2019-09-19 20:56:34 +01:00
|
|
|
node.Contact.Service.UpdateSelf(&newCapacity)
|
2019-09-13 12:53:48 +01:00
|
|
|
|
2020-02-19 18:32:53 +00:00
|
|
|
node.Contact.Chore.TriggerWait(ctx)
|
2019-09-13 12:53:48 +01:00
|
|
|
|
|
|
|
newInfo, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
firstUptime := oldInfo.Reputation.LastContactSuccess
|
|
|
|
secondUptime := newInfo.Reputation.LastContactSuccess
|
|
|
|
require.True(t, secondUptime.After(firstUptime))
|
|
|
|
|
|
|
|
require.Equal(t, newCapacity, newInfo.Capacity)
|
|
|
|
})
|
|
|
|
}
|
2019-09-19 20:56:34 +01:00
|
|
|
|
2020-02-26 02:39:44 +00:00
|
|
|
func TestServicePingSatellites(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 2, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
node := planet.StorageNodes[0]
|
|
|
|
node.Contact.Chore.Pause(ctx)
|
|
|
|
|
|
|
|
newCapacity := pb.NodeCapacity{
|
2020-03-23 20:24:11 +00:00
|
|
|
FreeDisk: 0,
|
2020-02-26 02:39:44 +00:00
|
|
|
}
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
info, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEqual(t, newCapacity, info.Capacity)
|
|
|
|
}
|
|
|
|
|
|
|
|
node.Contact.Service.UpdateSelf(&newCapacity)
|
|
|
|
err := node.Contact.Service.PingSatellites(ctx, 10*time.Second)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
info, err := satellite.Overlay.Service.Get(ctx, node.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, newCapacity, info.Capacity)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-27 16:47:57 +01:00
|
|
|
func TestLocalAndUpdateSelf(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]
|
|
|
|
var group errgroup.Group
|
|
|
|
group.Go(func() error {
|
|
|
|
_ = node.Contact.Service.Local()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
node.Contact.Service.UpdateSelf(&pb.NodeCapacity{})
|
|
|
|
_ = group.Wait()
|
|
|
|
})
|
|
|
|
}
|