2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-14 19:23:54 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package discovery_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-04 17:34:36 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-12-14 19:23:54 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCache_Refresh(t *testing.T) {
|
2019-02-05 17:03:16 +00:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-03-22 13:14:17 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
2019-02-05 17:03:16 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
node, err := satellite.Overlay.Service.Get(ctx, storageNode.ID())
|
|
|
|
if assert.NoError(t, err) {
|
|
|
|
assert.Equal(t, storageNode.Addr(), node.Address.Address)
|
|
|
|
}
|
2019-01-30 20:29:33 +00:00
|
|
|
}
|
2019-02-05 17:03:16 +00:00
|
|
|
})
|
2018-12-14 19:23:54 +00:00
|
|
|
}
|
2019-02-08 20:56:24 +00:00
|
|
|
|
|
|
|
func TestCache_Graveyard(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-03-22 13:14:17 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
2019-02-08 20:56:24 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
testnode := planet.StorageNodes[0]
|
|
|
|
offlineID := testnode.ID()
|
|
|
|
|
2019-04-22 16:22:52 +01:00
|
|
|
satellite.Kademlia.Service.RefreshBuckets.Pause()
|
|
|
|
|
|
|
|
satellite.Discovery.Service.Refresh.Pause()
|
2019-02-08 20:56:24 +00:00
|
|
|
satellite.Discovery.Service.Graveyard.Pause()
|
2019-04-22 16:22:52 +01:00
|
|
|
satellite.Discovery.Service.Discovery.Pause()
|
2019-02-08 20:56:24 +00:00
|
|
|
|
2019-04-23 23:45:50 +01:00
|
|
|
overlay := satellite.Overlay.Service
|
|
|
|
|
2019-04-04 17:34:36 +01:00
|
|
|
// mark node as offline in overlay cache
|
2019-04-23 23:45:50 +01:00
|
|
|
_, err := overlay.UpdateUptime(ctx, offlineID, false)
|
2019-04-04 17:34:36 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-04-23 23:45:50 +01:00
|
|
|
node, err := overlay.Get(ctx, offlineID)
|
2019-02-08 20:56:24 +00:00
|
|
|
assert.NoError(t, err)
|
2019-04-23 23:45:50 +01:00
|
|
|
assert.False(t, overlay.IsOnline(node))
|
2019-02-08 20:56:24 +00:00
|
|
|
|
|
|
|
satellite.Discovery.Service.Graveyard.TriggerWait()
|
|
|
|
|
2019-04-23 23:45:50 +01:00
|
|
|
found, err := overlay.Get(ctx, offlineID)
|
2019-02-08 20:56:24 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, offlineID, found.Id)
|
2019-04-23 23:45:50 +01:00
|
|
|
assert.True(t, overlay.IsOnline(found))
|
2019-02-08 20:56:24 +00:00
|
|
|
})
|
|
|
|
}
|