2019-02-01 13:32:28 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kademlia_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap/zaptest"
|
2019-02-08 20:35:59 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2019-02-01 13:32:28 +00:00
|
|
|
|
|
|
|
"storj.io/storj/bootstrap"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/storagenode"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMergePlanets(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
log := zaptest.NewLogger(t)
|
|
|
|
|
|
|
|
alpha, err := testplanet.NewCustom(log.Named("A"), testplanet.Config{
|
|
|
|
SatelliteCount: 2,
|
|
|
|
StorageNodeCount: 5,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
beta, err := testplanet.NewCustom(log.Named("B"), testplanet.Config{
|
|
|
|
SatelliteCount: 2,
|
|
|
|
StorageNodeCount: 5,
|
|
|
|
Identities: alpha.Identities(), // avoid using the same pregenerated identities
|
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2019-02-04 20:37:46 +00:00
|
|
|
Bootstrap: func(index int, config *bootstrap.Config) {
|
2019-02-01 13:32:28 +00:00
|
|
|
config.Kademlia.BootstrapAddr = alpha.Bootstrap.Addr()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer ctx.Check(alpha.Shutdown)
|
|
|
|
defer ctx.Check(beta.Shutdown)
|
|
|
|
|
2019-02-08 20:35:59 +00:00
|
|
|
// during planet.Start
|
|
|
|
// every satellite & storage node looks itself up from bootstrap
|
|
|
|
// every storage node pings bootstrap
|
|
|
|
// every satellite pings every storage node
|
2019-02-01 13:32:28 +00:00
|
|
|
alpha.Start(ctx)
|
|
|
|
beta.Start(ctx)
|
|
|
|
|
2019-09-17 21:14:49 +01:00
|
|
|
allSatellites := []*testplanet.SatelliteSystem{}
|
2019-02-08 20:35:59 +00:00
|
|
|
allSatellites = append(allSatellites, alpha.Satellites...)
|
|
|
|
allSatellites = append(allSatellites, beta.Satellites...)
|
|
|
|
|
|
|
|
// make satellites refresh buckets 10 times
|
|
|
|
var group errgroup.Group
|
|
|
|
for _, satellite := range allSatellites {
|
|
|
|
satellite := satellite
|
|
|
|
group.Go(func() error {
|
|
|
|
satellite.Kademlia.Service.SetBucketRefreshThreshold(0)
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
satellite.Kademlia.Service.RefreshBuckets.TriggerWait()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_ = group.Wait()
|
2019-02-01 13:32:28 +00:00
|
|
|
|
2019-09-17 21:14:49 +01:00
|
|
|
test := func(tag string, satellites []*testplanet.SatelliteSystem, storageNodes []*storagenode.Peer) string {
|
2019-02-01 13:32:28 +00:00
|
|
|
found, missing := 0, 0
|
|
|
|
for _, satellite := range satellites {
|
|
|
|
for _, storageNode := range storageNodes {
|
|
|
|
node, err := satellite.Overlay.Service.Get(ctx, storageNode.ID())
|
|
|
|
if assert.NoError(t, err, tag) {
|
|
|
|
found++
|
|
|
|
assert.Equal(t, storageNode.Addr(), node.Address.Address, tag)
|
|
|
|
} else {
|
|
|
|
missing++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s: Found %v out of %v (missing %v)", tag, found, found+missing, missing)
|
|
|
|
}
|
|
|
|
|
|
|
|
sumAA := test("A-A", alpha.Satellites, alpha.StorageNodes)
|
|
|
|
sumAB := test("A-B", alpha.Satellites, beta.StorageNodes)
|
|
|
|
sumBB := test("B-B", beta.Satellites, beta.StorageNodes)
|
|
|
|
sumBA := test("B-A", beta.Satellites, alpha.StorageNodes)
|
|
|
|
|
|
|
|
t.Log(sumAA)
|
|
|
|
t.Log(sumAB)
|
|
|
|
t.Log(sumBB)
|
|
|
|
t.Log(sumBA)
|
|
|
|
}
|