2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-03 12:17:14 +00:00
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2019-02-04 15:40:37 +00:00
|
|
|
"time"
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-02-04 15:40:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-04-08 19:15:19 +01:00
|
|
|
"storj.io/storj/pkg/storj"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testcontext"
|
|
|
|
"storj.io/storj/private/testplanet"
|
2018-11-03 12:17:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasic(t *testing.T) {
|
2019-02-04 15:40:37 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-04-08 19:15:19 +01:00
|
|
|
test := func(version storj.IDVersion) {
|
|
|
|
planet, err := testplanet.NewWithIdentityVersion(t, &version, 2, 4, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-04-08 19:15:19 +01:00
|
|
|
planet.Start(ctx)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-04-08 19:15:19 +01:00
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
t.Log("SATELLITE", satellite.ID(), satellite.Addr())
|
|
|
|
}
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
t.Log("STORAGE", storageNode.ID(), storageNode.Addr())
|
|
|
|
}
|
|
|
|
for _, uplink := range planet.Uplinks {
|
|
|
|
t.Log("UPLINK", uplink.ID(), uplink.Addr())
|
|
|
|
}
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-09-20 21:02:23 +01:00
|
|
|
for _, sat := range planet.Satellites {
|
|
|
|
satellite := sat.Local().Node
|
|
|
|
for _, sn := range planet.StorageNodes {
|
|
|
|
node := sn.Local()
|
2019-09-19 05:46:39 +01:00
|
|
|
conn, err := sn.Dialer.DialNode(ctx, &satellite)
|
2019-09-20 21:02:23 +01:00
|
|
|
require.NoError(t, err)
|
2019-09-27 16:47:57 +01:00
|
|
|
defer ctx.Check(conn.Close)
|
2019-09-19 05:46:39 +01:00
|
|
|
_, err = conn.NodeClient().CheckIn(ctx, &pb.CheckInRequest{
|
2019-09-20 21:02:23 +01:00
|
|
|
Address: node.GetAddress().GetAddress(),
|
|
|
|
Version: &node.Version,
|
|
|
|
Capacity: &node.Capacity,
|
|
|
|
Operator: &node.Operator,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 19:15:19 +01:00
|
|
|
// wait a bit to see whether some failures occur
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, version := range storj.IDVersions {
|
|
|
|
test(version)
|
|
|
|
}
|
2018-11-03 12:17:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 20:56:34 +01:00
|
|
|
// test that nodes get put into each satellite's overlay cache
|
|
|
|
func TestContact(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 2, StorageNodeCount: 5, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite0 := planet.Satellites[0]
|
|
|
|
satellite1 := planet.Satellites[1]
|
|
|
|
|
|
|
|
for _, n := range planet.StorageNodes {
|
|
|
|
_, err := satellite0.Overlay.Service.Get(ctx, n.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = satellite1.Overlay.Service.Get(ctx, n.ID())
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-11-03 12:17:14 +00:00
|
|
|
func BenchmarkCreate(b *testing.B) {
|
|
|
|
storageNodes := []int{4, 10, 100}
|
|
|
|
for _, count := range storageNodes {
|
2019-05-29 14:30:16 +01:00
|
|
|
storageNodeCount := count
|
|
|
|
b.Run(strconv.Itoa(storageNodeCount), func(b *testing.B) {
|
2018-11-03 12:17:14 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2019-05-29 14:30:16 +01:00
|
|
|
planet, err := testplanet.New(nil, 1, storageNodeCount, 1)
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(b, err)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
|
|
|
planet.Start(ctx)
|
|
|
|
|
|
|
|
err = planet.Shutdown()
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(b, err)
|
2018-11-03 12:17:14 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|