a5ff5016c9
* port changes * Merge remote-tracking branch 'upstream/master' * Merge remote-tracking branch 'upstream/master' * Merge remote-tracking branch 'upstream/master' * files created * Merge remote-tracking branch 'upstream/master' into coyle/kad-tests * wip * Merge remote-tracking branch 'upstream/master' into coyle/kad-tests * wip * remove bkad dependencie from tests * wip * wip * wip * wip * wip * updated coyle/kademlia * wip * cleanup * ports * overlay upgraded * linter fixes * piecestore kademlia newID * add changes from kad demo * PR comments addresses * go func * force travis build * fixed merge conflicts * fixed merge conflicts * Merge branch 'coyle/kad-tests' of https://github.com/coyle/storj into coyle/kad-tests * linter issues * linting issues * fixed merge conflicts * linter is stupid
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package overlay
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/grpc"
|
|
|
|
"storj.io/storj/internal/test"
|
|
"storj.io/storj/pkg/kademlia"
|
|
proto "storj.io/storj/protos/overlay" // naming proto to avoid confusion with this package
|
|
)
|
|
|
|
func TestFindStorageNodes(t *testing.T) {
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
|
|
assert.NoError(t, err)
|
|
|
|
id, err := kademlia.NewID()
|
|
assert.NoError(t, err)
|
|
id2, err := kademlia.NewID()
|
|
assert.NoError(t, err)
|
|
|
|
srv := NewMockServer(test.KvStore{id.String(): NewNodeAddressValue(t, "127.0.0.1:9090"), id2.String(): NewNodeAddressValue(t, "127.0.0.1:9090")})
|
|
assert.NotNil(t, srv)
|
|
|
|
go srv.Serve(lis)
|
|
defer srv.Stop()
|
|
|
|
address := lis.Addr().String()
|
|
c, err := NewClient(&address, grpc.WithInsecure())
|
|
assert.NoError(t, err)
|
|
|
|
r, err := c.FindStorageNodes(context.Background(), &proto.FindStorageNodesRequest{})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, r)
|
|
|
|
assert.Len(t, r.Nodes, 2)
|
|
}
|
|
|
|
func TestOverlayLookup(t *testing.T) {
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 0))
|
|
assert.NoError(t, err)
|
|
|
|
id, err := kademlia.NewID()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
srv := NewMockServer(test.KvStore{id.String(): NewNodeAddressValue(t, "127.0.0.1:9090")})
|
|
go srv.Serve(lis)
|
|
defer srv.Stop()
|
|
|
|
address := lis.Addr().String()
|
|
c, err := NewClient(&address, grpc.WithInsecure())
|
|
assert.NoError(t, err)
|
|
|
|
r, err := c.Lookup(context.Background(), &proto.LookupRequest{NodeID: id.String()})
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, r)
|
|
}
|