From bbfe7f401f988a59dbbbdf5a9dccb54391cc71ad Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 2 Jun 2016 14:49:30 -0700 Subject: [PATCH] integration: always return active client In the integration test, we sometimes stop/restart an etcd server. Now our client has internal connection monitoring logic that might set conn to nil when there is a connection failure and the redial also fails. Chaning randClient to always return a client with active connection to make integration test reliable. --- integration/cluster.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/integration/cluster.go b/integration/cluster.go index c339e37c9..7561df298 100644 --- a/integration/cluster.go +++ b/integration/cluster.go @@ -795,7 +795,15 @@ func (c *ClusterV3) Terminate(t *testing.T) { } func (c *ClusterV3) RandClient() *clientv3.Client { - return c.clients[rand.Intn(len(c.clients))] + 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") } func (c *ClusterV3) Client(i int) *clientv3.Client {