浏览代码

clientv3: panic if ActiveConnection tries to return non-nil connection

Anthony Romano 9 年之前
父节点
当前提交
7dfe7db243
共有 3 个文件被更改,包括 5 次插入10 次删除
  1. 3 0
      clientv3/client.go
  2. 1 1
      clientv3/txn_test.go
  3. 1 9
      integration/cluster.go

+ 3 - 0
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
 }
 

+ 1 - 1
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() {

+ 1 - 9
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 {