2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-06-29 19:28:06 +01:00
|
|
|
// See LICENSE for copying information.
|
2018-12-14 10:44:48 +00:00
|
|
|
package transport_test
|
2018-06-29 19:28:06 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-12-14 10:44:48 +00:00
|
|
|
"fmt"
|
2018-06-29 19:28:06 +01:00
|
|
|
"testing"
|
2018-12-14 10:44:48 +00:00
|
|
|
"time"
|
2018-06-29 19:28:06 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-07-03 09:35:01 +01:00
|
|
|
|
2018-12-14 10:44:48 +00:00
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-12-14 10:44:48 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
"storj.io/storj/pkg/transport"
|
2018-06-29 19:28:06 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDialNode(t *testing.T) {
|
2018-12-14 10:44:48 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
2018-08-24 05:01:03 +01:00
|
|
|
|
2018-12-14 10:44:48 +00:00
|
|
|
planet, err := testplanet.New(t, 0, 2, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2018-08-24 05:01:03 +01:00
|
|
|
}
|
2018-12-14 10:44:48 +00:00
|
|
|
defer ctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(ctx)
|
|
|
|
|
|
|
|
client := transport.NewClient(planet.StorageNodes[0].Identity)
|
2018-06-29 19:28:06 +01:00
|
|
|
|
2018-12-14 10:44:48 +00:00
|
|
|
{ // DialNode with invalid targets
|
|
|
|
targets := []*pb.Node{
|
2019-01-02 18:47:34 +00:00
|
|
|
{
|
|
|
|
Id: storj.NodeID{},
|
|
|
|
Address: nil,
|
|
|
|
Type: pb.NodeType_STORAGE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: storj.NodeID{},
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
},
|
|
|
|
Type: pb.NodeType_STORAGE,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Id: storj.NodeID{123},
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: "127.0.0.1:100",
|
|
|
|
},
|
|
|
|
Type: pb.NodeType_STORAGE,
|
|
|
|
},
|
2018-12-14 10:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, target := range targets {
|
|
|
|
tag := fmt.Sprintf("%+v", target)
|
|
|
|
|
|
|
|
timedCtx, cancel := context.WithTimeout(ctx, time.Second)
|
2019-02-01 17:40:35 +00:00
|
|
|
conn, err := client.DialNode(timedCtx, target)
|
2018-12-14 10:44:48 +00:00
|
|
|
cancel()
|
|
|
|
assert.Error(t, err, tag)
|
|
|
|
assert.Nil(t, conn, tag)
|
|
|
|
}
|
2018-06-29 19:28:06 +01:00
|
|
|
}
|
2018-12-14 10:44:48 +00:00
|
|
|
|
|
|
|
{ // DialNode with valid target
|
|
|
|
timedCtx, cancel := context.WithTimeout(ctx, time.Second)
|
|
|
|
conn, err := client.DialNode(timedCtx, &pb.Node{
|
|
|
|
Id: planet.StorageNodes[1].ID(),
|
|
|
|
Address: &pb.NodeAddress{
|
|
|
|
Transport: pb.NodeTransport_TCP_TLS_GRPC,
|
|
|
|
Address: planet.StorageNodes[1].Addr(),
|
|
|
|
},
|
2019-01-02 18:47:34 +00:00
|
|
|
Type: pb.NodeType_STORAGE,
|
2019-02-01 17:40:35 +00:00
|
|
|
})
|
2018-12-14 10:44:48 +00:00
|
|
|
cancel()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, conn)
|
|
|
|
|
|
|
|
assert.NoError(t, conn.Close())
|
2018-06-29 19:28:06 +01:00
|
|
|
}
|
2018-12-14 10:44:48 +00:00
|
|
|
|
|
|
|
{ // DialAddress with valid address
|
|
|
|
timedCtx, cancel := context.WithTimeout(ctx, time.Second)
|
2019-02-01 17:40:35 +00:00
|
|
|
conn, err := client.DialAddress(timedCtx, planet.StorageNodes[1].Addr())
|
2018-12-14 10:44:48 +00:00
|
|
|
cancel()
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, conn)
|
|
|
|
|
|
|
|
assert.NoError(t, conn.Close())
|
2018-06-29 19:28:06 +01:00
|
|
|
}
|
|
|
|
}
|