mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: panic if ActiveConnection tries to return non-nil connection
This commit is contained in:
parent
267d1cb16f
commit
7dfe7db243
@ -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
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTxnPanics(t *testing.T) {
|
||||
kv := NewKV(&Client{})
|
||||
kv := &kv{}
|
||||
|
||||
errc := make(chan string)
|
||||
df := func() {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user