Ensure overlay tests run against postgres (#1232)
This commit is contained in:
parent
bb11d83ed0
commit
30f89b0362
@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/overlay"
|
||||
"storj.io/storj/pkg/pb"
|
||||
@ -19,6 +20,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCache_Database(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
|
@ -18,203 +18,187 @@ import (
|
||||
)
|
||||
|
||||
func TestChoose(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
t.Parallel()
|
||||
|
||||
planet, err := testplanet.New(t, 1, 8, 1)
|
||||
require.NoError(t, err)
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 8, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
planet.Start(ctx)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
limit int
|
||||
space int64
|
||||
bandwidth int64
|
||||
}{
|
||||
{
|
||||
limit: 4,
|
||||
space: 0,
|
||||
bandwidth: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range cases {
|
||||
newNodes, err := oc.Choose(ctx, overlay.Options{
|
||||
Amount: v.limit,
|
||||
Space: v.space,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, newNodes, v.limit)
|
||||
for _, n := range newNodes {
|
||||
assert.True(t, n.GetRestrictions().GetFreeDisk() >= v.space)
|
||||
assert.True(t, n.GetRestrictions().GetFreeBandwidth() >= v.bandwidth)
|
||||
cases := []struct {
|
||||
limit int
|
||||
space int64
|
||||
bandwidth int64
|
||||
}{
|
||||
{
|
||||
limit: 4,
|
||||
space: 0,
|
||||
bandwidth: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range cases {
|
||||
newNodes, err := oc.Choose(ctx, overlay.Options{
|
||||
Amount: v.limit,
|
||||
Space: v.space,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, newNodes, v.limit)
|
||||
for _, n := range newNodes {
|
||||
assert.True(t, n.GetRestrictions().GetFreeDisk() >= v.space)
|
||||
assert.True(t, n.GetRestrictions().GetFreeBandwidth() >= v.bandwidth)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLookup(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
t.Parallel()
|
||||
|
||||
planet, err := testplanet.New(t, 1, 4, 1)
|
||||
require.NoError(t, err)
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
planet.Start(ctx)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nid1 := planet.StorageNodes[0].ID()
|
||||
|
||||
nid1 := planet.StorageNodes[0].ID()
|
||||
|
||||
cases := []struct {
|
||||
nodeID storj.NodeID
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
nodeID: nid1,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
nodeID: storj.NodeID{1},
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range cases {
|
||||
n, err := oc.Lookup(ctx, v.nodeID)
|
||||
if v.expectErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, n.Id.String(), v.nodeID.String())
|
||||
cases := []struct {
|
||||
nodeID storj.NodeID
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
nodeID: nid1,
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
nodeID: storj.NodeID{1},
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range cases {
|
||||
n, err := oc.Lookup(ctx, v.nodeID)
|
||||
if v.expectErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
if assert.NotNil(t, n) {
|
||||
assert.Equal(t, v.nodeID.String(), n.Id.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBulkLookup(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
t.Parallel()
|
||||
|
||||
planet, err := testplanet.New(t, 1, 4, 1)
|
||||
require.NoError(t, err)
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
planet.Start(ctx)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nid1 := planet.StorageNodes[0].ID()
|
||||
nid2 := planet.StorageNodes[1].ID()
|
||||
nid3 := planet.StorageNodes[2].ID()
|
||||
|
||||
nid1 := planet.StorageNodes[0].ID()
|
||||
nid2 := planet.StorageNodes[1].ID()
|
||||
nid3 := planet.StorageNodes[2].ID()
|
||||
|
||||
cases := []struct {
|
||||
nodeIDs storj.NodeIDList
|
||||
expectedCalls int
|
||||
}{
|
||||
{
|
||||
nodeIDs: storj.NodeIDList{nid1, nid2, nid3},
|
||||
expectedCalls: 1,
|
||||
},
|
||||
}
|
||||
for _, v := range cases {
|
||||
resNodes, err := oc.BulkLookup(ctx, v.nodeIDs)
|
||||
assert.NoError(t, err)
|
||||
for i, n := range resNodes {
|
||||
assert.Equal(t, n.Id, v.nodeIDs[i])
|
||||
cases := []struct {
|
||||
nodeIDs storj.NodeIDList
|
||||
expectedCalls int
|
||||
}{
|
||||
{
|
||||
nodeIDs: storj.NodeIDList{nid1, nid2, nid3},
|
||||
expectedCalls: 1,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, len(resNodes), len(v.nodeIDs))
|
||||
}
|
||||
for _, v := range cases {
|
||||
resNodes, err := oc.BulkLookup(ctx, v.nodeIDs)
|
||||
assert.NoError(t, err)
|
||||
for i, n := range resNodes {
|
||||
if assert.NotNil(t, n) {
|
||||
assert.Equal(t, v.nodeIDs[i], n.Id)
|
||||
}
|
||||
}
|
||||
assert.Equal(t, len(v.nodeIDs), len(resNodes))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBulkLookupV2(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
t.Parallel()
|
||||
|
||||
planet, err := testplanet.New(t, 1, 4, 1)
|
||||
require.NoError(t, err)
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
planet.Start(ctx)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
oc, err := planet.Uplinks[0].DialOverlay(planet.Satellites[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nid1 := planet.StorageNodes[0].ID()
|
||||
nid2 := planet.StorageNodes[1].ID()
|
||||
nid3 := planet.StorageNodes[2].ID()
|
||||
nid4 := storj.NodeID{4}
|
||||
nid5 := storj.NodeID{5}
|
||||
|
||||
cache := planet.Satellites[0].Overlay.Service
|
||||
n1 := &pb.Node{Id: nid1}
|
||||
n2 := &pb.Node{Id: nid2}
|
||||
n3 := &pb.Node{Id: nid3}
|
||||
|
||||
nid1 := storj.NodeID{1}
|
||||
nid2 := storj.NodeID{2}
|
||||
nid3 := storj.NodeID{3}
|
||||
nid4 := storj.NodeID{4}
|
||||
nid5 := storj.NodeID{5}
|
||||
|
||||
n1 := &pb.Node{Id: storj.NodeID{1}}
|
||||
n2 := &pb.Node{Id: storj.NodeID{2}}
|
||||
n3 := &pb.Node{Id: storj.NodeID{3}}
|
||||
|
||||
nodes := []*pb.Node{n1, n2, n3}
|
||||
for _, n := range nodes {
|
||||
assert.NoError(t, cache.Put(ctx, n.Id, *n))
|
||||
}
|
||||
|
||||
{ // empty id
|
||||
_, err := oc.BulkLookup(ctx, storj.NodeIDList{})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
{ // valid ids
|
||||
idList := storj.NodeIDList{nid1, nid2, nid3}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i, n := range ns {
|
||||
assert.Equal(t, n.Id, idList[i])
|
||||
{ // empty id
|
||||
_, err := oc.BulkLookup(ctx, storj.NodeIDList{})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
{ // missing ids
|
||||
idList := storj.NodeIDList{nid4, nid5}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
{ // valid ids
|
||||
idList := storj.NodeIDList{nid1, nid2, nid3}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []*pb.Node{nil, nil}, ns)
|
||||
}
|
||||
|
||||
{ // different order and missing
|
||||
idList := storj.NodeIDList{nid3, nid4, nid1, nid2, nid5}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedNodes := []*pb.Node{n3, nil, n1, n2, nil}
|
||||
for i, n := range ns {
|
||||
if n == nil {
|
||||
assert.Nil(t, expectedNodes[i])
|
||||
} else {
|
||||
assert.Equal(t, n.Id, expectedNodes[i].Id)
|
||||
for i, n := range ns {
|
||||
if assert.NotNil(t, n) {
|
||||
assert.Equal(t, idList[i], n.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ // missing ids
|
||||
idList := storj.NodeIDList{nid4, nid5}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, []*pb.Node{nil, nil}, ns)
|
||||
}
|
||||
|
||||
{ // different order and missing
|
||||
idList := storj.NodeIDList{nid3, nid4, nid1, nid2, nid5}
|
||||
ns, err := oc.BulkLookup(ctx, idList)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedNodes := []*pb.Node{n3, nil, n1, n2, nil}
|
||||
for i, n := range ns {
|
||||
if n == nil {
|
||||
assert.Nil(t, n)
|
||||
} else {
|
||||
if assert.NotNil(t, n) {
|
||||
assert.Equal(t, expectedNodes[i].Id, n.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -19,211 +19,202 @@ import (
|
||||
)
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
planet, err := testplanet.New(t, 1, 4, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
satellite := planet.Satellites[0]
|
||||
server := satellite.Overlay.Endpoint
|
||||
// TODO: handle cleanup
|
||||
|
||||
planet.Start(ctx)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
{ // Lookup
|
||||
result, err := server.Lookup(ctx, &pb.LookupRequest{
|
||||
NodeId: planet.StorageNodes[0].ID(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
assert.Equal(t, result.Node.Address.Address, planet.StorageNodes[0].Addr())
|
||||
}
|
||||
|
||||
satellite := planet.Satellites[0]
|
||||
server := satellite.Overlay.Endpoint
|
||||
// TODO: handle cleanup
|
||||
{ // BulkLookup
|
||||
result, err := server.BulkLookup(ctx, &pb.LookupRequests{
|
||||
LookupRequest: []*pb.LookupRequest{
|
||||
{NodeId: planet.StorageNodes[0].ID()},
|
||||
{NodeId: planet.StorageNodes[1].ID()},
|
||||
{NodeId: planet.StorageNodes[2].ID()},
|
||||
},
|
||||
})
|
||||
|
||||
{ // Lookup
|
||||
result, err := server.Lookup(ctx, &pb.LookupRequest{
|
||||
NodeId: planet.StorageNodes[0].ID(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
assert.Equal(t, result.Node.Address.Address, planet.StorageNodes[0].Addr())
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
require.Len(t, result.LookupResponse, 3)
|
||||
|
||||
{ // BulkLookup
|
||||
result, err := server.BulkLookup(ctx, &pb.LookupRequests{
|
||||
LookupRequest: []*pb.LookupRequest{
|
||||
{NodeId: planet.StorageNodes[0].ID()},
|
||||
{NodeId: planet.StorageNodes[1].ID()},
|
||||
{NodeId: planet.StorageNodes[2].ID()},
|
||||
},
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, result)
|
||||
require.Len(t, result.LookupResponse, 3)
|
||||
|
||||
for i, resp := range result.LookupResponse {
|
||||
if assert.NotNil(t, resp.Node) {
|
||||
assert.Equal(t, resp.Node.Address.Address, planet.StorageNodes[i].Addr())
|
||||
for i, resp := range result.LookupResponse {
|
||||
if assert.NotNil(t, resp.Node) {
|
||||
assert.Equal(t, resp.Node.Address.Address, planet.StorageNodes[i].Addr())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestNodeSelection(t *testing.T) {
|
||||
ctx := testcontext.New(t)
|
||||
defer ctx.Cleanup()
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 10, UplinkCount: 1,
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
var err error
|
||||
satellite := planet.Satellites[0]
|
||||
|
||||
planet, err := testplanet.New(t, 1, 10, 0)
|
||||
require.NoError(t, err)
|
||||
planet.Start(ctx)
|
||||
defer ctx.Check(planet.Shutdown)
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
satellite := planet.Satellites[0]
|
||||
// This sets a reputable audit count for a certain number of nodes.
|
||||
for i, node := range planet.StorageNodes {
|
||||
for k := 0; k < i; k++ {
|
||||
_, err := satellite.DB.StatDB().UpdateAuditSuccess(ctx, node.ID(), true)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// This sets a reputable audit count for a certain number of nodes.
|
||||
for i, node := range planet.StorageNodes {
|
||||
for k := 0; k < i; k++ {
|
||||
_, err := satellite.DB.StatDB().UpdateAuditSuccess(ctx, node.ID(), true)
|
||||
// ensure all storagenodes are in overlay service
|
||||
for _, storageNode := range planet.StorageNodes {
|
||||
err = satellite.Overlay.Service.Put(ctx, storageNode.ID(), storageNode.Local())
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
// ensure all storagenodes are in overlay service
|
||||
for _, storageNode := range planet.StorageNodes {
|
||||
err = satellite.Overlay.Service.Put(ctx, storageNode.ID(), storageNode.Local())
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
type test struct {
|
||||
Preferences overlay.NodeSelectionConfig
|
||||
ExcludeCount int
|
||||
RequestCount int64
|
||||
ExpectedCount int
|
||||
ShouldFailWith *errs.Class
|
||||
}
|
||||
|
||||
for i, tt := range []test{
|
||||
{ // all reputable nodes, only reputable nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{ // all reputable nodes, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{ // all reputable nodes except one, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 1,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 6,
|
||||
},
|
||||
{ // 50-50 reputable and new nodes, reputable and new nodes requested (new node ratio 1.0)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 4,
|
||||
},
|
||||
{ // 50-50 reputable and new nodes, reputable and new nodes requested (new node ratio 0.5)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 0.5,
|
||||
},
|
||||
RequestCount: 4,
|
||||
ExpectedCount: 6,
|
||||
},
|
||||
{ // all new nodes except one, reputable and new nodes requested (happy path)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 8,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 2,
|
||||
},
|
||||
{ // all new nodes except one, reputable and new nodes requested (not happy path)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 9,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 3,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
{ // all new nodes, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 50,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 2,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
{ // audit threshold edge case (1)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 9,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 1,
|
||||
},
|
||||
{ // audit threshold edge case (2)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 1,
|
||||
},
|
||||
{ // excluded node ids being excluded
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
ExcludeCount: 7,
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 3,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
} {
|
||||
t.Logf("#%2d. %+v", i, tt)
|
||||
endpoint := planet.Satellites[0].Overlay.Endpoint
|
||||
|
||||
var excludedNodes []storj.NodeID
|
||||
for _, storageNode := range planet.StorageNodes[:tt.ExcludeCount] {
|
||||
excludedNodes = append(excludedNodes, storageNode.ID())
|
||||
type test struct {
|
||||
Preferences overlay.NodeSelectionConfig
|
||||
ExcludeCount int
|
||||
RequestCount int64
|
||||
ExpectedCount int
|
||||
ShouldFailWith *errs.Class
|
||||
}
|
||||
|
||||
response, err := endpoint.FindStorageNodesWithPreferences(ctx,
|
||||
&pb.FindStorageNodesRequest{
|
||||
Opts: &pb.OverlayOptions{
|
||||
Restrictions: &pb.NodeRestrictions{
|
||||
FreeBandwidth: 0,
|
||||
FreeDisk: 0,
|
||||
},
|
||||
Amount: tt.RequestCount,
|
||||
ExcludedNodes: excludedNodes,
|
||||
for i, tt := range []test{
|
||||
{ // all reputable nodes, only reputable nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
}, &tt.Preferences)
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{ // all reputable nodes, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 5,
|
||||
},
|
||||
{ // all reputable nodes except one, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 1,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 6,
|
||||
},
|
||||
{ // 50-50 reputable and new nodes, reputable and new nodes requested (new node ratio 1.0)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 4,
|
||||
},
|
||||
{ // 50-50 reputable and new nodes, reputable and new nodes requested (new node ratio 0.5)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 0.5,
|
||||
},
|
||||
RequestCount: 4,
|
||||
ExpectedCount: 6,
|
||||
},
|
||||
{ // all new nodes except one, reputable and new nodes requested (happy path)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 8,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 2,
|
||||
},
|
||||
{ // all new nodes except one, reputable and new nodes requested (not happy path)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 9,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 3,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
{ // all new nodes, reputable and new nodes requested
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 50,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 2,
|
||||
ExpectedCount: 2,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
{ // audit threshold edge case (1)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 9,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 1,
|
||||
},
|
||||
{ // audit threshold edge case (2)
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 0,
|
||||
NewNodePercentage: 1,
|
||||
},
|
||||
RequestCount: 1,
|
||||
ExpectedCount: 1,
|
||||
},
|
||||
{ // excluded node ids being excluded
|
||||
Preferences: overlay.NodeSelectionConfig{
|
||||
NewNodeAuditThreshold: 5,
|
||||
NewNodePercentage: 0,
|
||||
},
|
||||
ExcludeCount: 7,
|
||||
RequestCount: 5,
|
||||
ExpectedCount: 3,
|
||||
ShouldFailWith: &overlay.ErrNotEnoughNodes,
|
||||
},
|
||||
} {
|
||||
t.Logf("#%2d. %+v", i, tt)
|
||||
endpoint := planet.Satellites[0].Overlay.Endpoint
|
||||
|
||||
t.Log(len(response.Nodes), err)
|
||||
if tt.ShouldFailWith != nil {
|
||||
assert.Error(t, err)
|
||||
assert.True(t, tt.ShouldFailWith.Has(err))
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
var excludedNodes []storj.NodeID
|
||||
for _, storageNode := range planet.StorageNodes[:tt.ExcludeCount] {
|
||||
excludedNodes = append(excludedNodes, storageNode.ID())
|
||||
}
|
||||
|
||||
response, err := endpoint.FindStorageNodesWithPreferences(ctx,
|
||||
&pb.FindStorageNodesRequest{
|
||||
Opts: &pb.OverlayOptions{
|
||||
Restrictions: &pb.NodeRestrictions{
|
||||
FreeBandwidth: 0,
|
||||
FreeDisk: 0,
|
||||
},
|
||||
Amount: tt.RequestCount,
|
||||
ExcludedNodes: excludedNodes,
|
||||
},
|
||||
}, &tt.Preferences)
|
||||
|
||||
t.Log(len(response.Nodes), err)
|
||||
if tt.ShouldFailWith != nil {
|
||||
assert.Error(t, err)
|
||||
assert.True(t, tt.ShouldFailWith.Has(err))
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.ExpectedCount, len(response.Nodes))
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.ExpectedCount, len(response.Nodes))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user