storj/pkg/node/node_test.go

143 lines
3.2 KiB
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
Mutex/nsclient- WIP (#104) * working on put request for nsclient * working on put request for nsclient * netstate put * netstate put * wip testing client * wip - testing client and working through some errors * wip - testing client and working through some errors * put request works * put request works for client * get request working * get request working * get request working-minor edit * get request working-minor edit * list request works * list request works * working through delete error * working through delete error * fixed exp client, still working through delete error * fixed exp client, still working through delete error * delete works; fixed formatting issues * delete works; fixed formatting issues * deleted comment * deleted comment * resolving merge conflicts * resolving merge conflict * fixing merge conflict * implemented and modified kayloyans paths file * working on testing * added test for path_test.go * fixed string, read through netstate test * deleted env variables * initial commit for mocking out grpc client- got it working * mocked grpc client * mock put passed test * 2 tests pass for PUT with mock * put requests test pass, wip- want mini review * get tests pass mock * list test working * initial commit for list test * all list req. working, starting on delete tests * delete tests passed * cleaned up tests * resolved merge conflicts * resolved merge conflicts * fixed linter errors * fixed error found in travis * initial commit for fixes from PR comments * fixed pr comments and linting * added error handling for api creds, and rebased * fixes from dennis comments * fixed pr with dennis suggestioon * added copyrights to files * fixed casing per dennis great comment * fixed travis complaint on sprintf
2018-07-19 23:57:22 +01:00
// See LICENSE for copying information.
2018-12-12 15:40:33 +00:00
package node_test
import (
2018-12-12 15:40:33 +00:00
"fmt"
"testing"
2018-12-12 15:40:33 +00:00
"time"
"github.com/stretchr/testify/assert"
2018-12-12 15:40:33 +00:00
"golang.org/x/sync/errgroup"
2018-10-29 14:16:36 +00:00
"storj.io/storj/internal/testcontext"
2018-12-12 15:40:33 +00:00
"storj.io/storj/internal/testplanet"
"storj.io/storj/pkg/pb"
2018-12-12 15:40:33 +00:00
"storj.io/storj/pkg/storj"
"storj.io/storj/pkg/utils"
)
2018-12-12 15:40:33 +00:00
func TestClient(t *testing.T) {
2018-10-29 14:16:36 +00:00
ctx := testcontext.New(t)
defer ctx.Cleanup()
2018-12-12 15:40:33 +00:00
planet, err := testplanet.New(t, 1, 4, 0)
if err != nil {
t.Fatal(err)
}
2018-12-12 15:40:33 +00:00
defer ctx.Check(planet.Shutdown)
2018-12-12 15:40:33 +00:00
planet.Start(ctx)
2018-12-12 15:40:33 +00:00
time.Sleep(2 * time.Second)
2019-01-10 13:13:27 +00:00
// TODO: also use satellites
peers := planet.StorageNodes
2018-12-12 15:40:33 +00:00
{ // Ping
client, err := planet.StorageNodes[0].NewNodeClient()
assert.NoError(t, err)
2018-12-12 15:40:33 +00:00
defer ctx.Check(client.Disconnect)
var group errgroup.Group
for i := range peers {
peer := peers[i]
group.Go(func() error {
2019-01-10 13:13:27 +00:00
pinged, err := client.Ping(ctx, peer.Local())
2018-12-12 15:40:33 +00:00
var pingErr error
if !pinged {
pingErr = fmt.Errorf("ping to %s should have succeeded", peer.ID())
}
return utils.CombineErrors(pingErr, err)
})
}
defer ctx.Check(group.Wait)
}
2018-12-12 15:40:33 +00:00
{ // Lookup
client, err := planet.StorageNodes[1].NewNodeClient()
assert.NoError(t, err)
2018-12-12 15:40:33 +00:00
defer ctx.Check(client.Disconnect)
2018-12-12 15:40:33 +00:00
var group errgroup.Group
2018-12-12 15:40:33 +00:00
for i := range peers {
peer := peers[i]
group.Go(func() error {
for _, target := range peers {
errTag := fmt.Errorf("lookup peer:%s target:%s", peer.ID(), target.ID())
2019-01-10 13:13:27 +00:00
peer.Local().Type.DPanicOnInvalid("test client peer")
target.Local().Type.DPanicOnInvalid("test client target")
results, err := client.Lookup(ctx, peer.Local(), target.Local())
2018-12-12 15:40:33 +00:00
if err != nil {
return utils.CombineErrors(errTag, err)
}
2018-12-12 15:40:33 +00:00
if containsResult(results, target.ID()) {
continue
}
2018-12-12 15:40:33 +00:00
// with small network we expect to return everything
if len(results) != planet.Size() {
return utils.CombineErrors(errTag, fmt.Errorf("expected %d got %d: %s", planet.Size(), len(results), pb.NodesToIDs(results)))
}
2018-12-12 15:40:33 +00:00
return nil
}
return nil
})
}
2018-12-12 15:40:33 +00:00
defer ctx.Check(group.Wait)
}
2018-12-12 15:40:33 +00:00
{ // Lookup
client, err := planet.StorageNodes[2].NewNodeClient()
assert.NoError(t, err)
defer ctx.Check(client.Disconnect)
targets := []storj.NodeID{
{}, // empty target
{255}, // non-empty
}
var group errgroup.Group
for i := range targets {
target := targets[i]
for i := range peers {
peer := peers[i]
group.Go(func() error {
errTag := fmt.Errorf("invalid lookup peer:%s target:%s", peer.ID(), target)
2019-01-10 13:13:27 +00:00
peer.Local().Type.DPanicOnInvalid("peer info")
results, err := client.Lookup(ctx, peer.Local(), pb.Node{Id: target, Type: pb.NodeType_STORAGE})
2018-12-12 15:40:33 +00:00
if err != nil {
return utils.CombineErrors(errTag, err)
}
// with small network we expect to return everything
if len(results) != planet.Size() {
return utils.CombineErrors(errTag, fmt.Errorf("expected %d got %d: %s", planet.Size(), len(results), pb.NodesToIDs(results)))
}
return nil
})
}
}
defer ctx.Check(group.Wait)
}
}
2018-12-12 15:40:33 +00:00
func containsResult(nodes []*pb.Node, target storj.NodeID) bool {
for _, node := range nodes {
if node.Id == target {
return true
}
}
return false
}