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) {
|
|
|
|
nodeDossier := planet.StorageNodes[0].Local()
|
|
|
|
pingStats := planet.StorageNodes[0].Contact.PingStats
|
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
conn, err := planet.Satellites[0].Dialer.DialNode(ctx, &nodeDossier.Node)
|
2019-09-06 17:14:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(conn.Close)
|
|
|
|
|
2019-12-22 15:07:50 +00:00
|
|
|
resp, err := pb.NewDRPCContactClient(conn.Raw()).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
|
|
|
|
2019-10-28 14:04:31 +00:00
|
|
|
time.Sleep(time.Second) //HACKFIX: windows has large time granularity
|
|
|
|
|
2019-12-22 15:07:50 +00:00
|
|
|
resp, err = pb.NewDRPCContactClient(conn.Raw()).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{
|
|
|
|
FreeBandwidth: 0,
|
|
|
|
FreeDisk: 0,
|
|
|
|
}
|
|
|
|
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
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|