From 7dfe7db2431bdfe1247cbc5fbc2efabaed67aae6 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 3 Jun 2016 00:16:52 -0700 Subject: [PATCH] clientv3: panic if ActiveConnection tries to return non-nil connection --- clientv3/client.go | 3 +++ clientv3/txn_test.go | 2 +- integration/cluster.go | 10 +--------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/clientv3/client.go b/clientv3/client.go index 8ad7f0cf9..349014d14 100644 --- a/clientv3/client.go +++ b/clientv3/client.go @@ -292,6 +292,9 @@ func newClient(cfg *Config) (*Client, error) { func (c *Client) ActiveConnection() *grpc.ClientConn { c.mu.RLock() defer c.mu.RUnlock() + if c.conn == nil { + panic("trying to return nil active connection") + } return c.conn } diff --git a/clientv3/txn_test.go b/clientv3/txn_test.go index 4bedf21f1..e936d34ee 100644 --- a/clientv3/txn_test.go +++ b/clientv3/txn_test.go @@ -20,7 +20,7 @@ import ( ) func TestTxnPanics(t *testing.T) { - kv := NewKV(&Client{}) + kv := &kv{} errc := make(chan string) df := func() { diff --git a/integration/cluster.go b/integration/cluster.go index 7561df298..c339e37c9 100644 --- a/integration/cluster.go +++ b/integration/cluster.go @@ -795,15 +795,7 @@ func (c *ClusterV3) Terminate(t *testing.T) { } func (c *ClusterV3) RandClient() *clientv3.Client { - for i := 0; i < 100; i++ { - cli := c.clients[rand.Intn(len(c.clients))] - if cli.ActiveConnection() == nil { - time.Sleep(10 * time.Millisecond) - continue - } - return cli - } - panic("failed to get a active client") + return c.clients[rand.Intn(len(c.clients))] } func (c *ClusterV3) Client(i int) *clientv3.Client {