From 46971fa1db466b2f0db7cd133b8b3492c5777873 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Wed, 12 Apr 2017 17:55:02 -0700 Subject: [PATCH] integration: test client can dial endpoints not in balancer --- clientv3/integration/dial_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/clientv3/integration/dial_test.go b/clientv3/integration/dial_test.go index 48002ded2..a2ca4ab9f 100644 --- a/clientv3/integration/dial_test.go +++ b/clientv3/integration/dial_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/coreos/etcd/clientv3" + pb "github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/integration" "github.com/coreos/etcd/pkg/testutil" "golang.org/x/net/context" @@ -109,3 +110,26 @@ func TestRejectOldCluster(t *testing.T) { } cli.Close() } + +// TestDialForeignEndpoint checks an endpoint that is not registered +// with the balancer can be dialed. +func TestDialForeignEndpoint(t *testing.T) { + defer testutil.AfterTest(t) + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 2}) + defer clus.Terminate(t) + + conn, err := clus.Client(0).Dial(clus.Client(1).Endpoints()[0]) + if err != nil { + t.Fatal(err) + } + defer conn.Close() + + // grpc can return a lazy connection that's not connected yet; confirm + // that it can communicate with the cluster. + kvc := clientv3.NewKVFromKVClient(pb.NewKVClient(conn)) + ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second) + defer cancel() + if _, gerr := kvc.Get(ctx, "abc"); gerr != nil { + t.Fatal(err) + } +}