From 27a30768e1588d00ac0bcd00da786c7b2c3cfadd Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 18 Jul 2016 15:02:36 -0700 Subject: [PATCH] integration: drain keepalives in TestLeaseKeepAliveCloseAfterDisconnectRevoke Fixes #5900 --- clientv3/integration/lease_test.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go index 769a56942..00a21e371 100644 --- a/clientv3/integration/lease_test.go +++ b/clientv3/integration/lease_test.go @@ -359,7 +359,8 @@ func TestLeaseKeepAliveCloseAfterDisconnectRevoke(t *testing.T) { if kerr != nil { t.Fatal(kerr) } - if kresp := <-rc; kresp.ID != resp.ID { + kresp := <-rc + if kresp.ID != resp.ID { t.Fatalf("ID = %x, want %x", kresp.ID, resp.ID) } @@ -374,13 +375,14 @@ func TestLeaseKeepAliveCloseAfterDisconnectRevoke(t *testing.T) { clus.Members[0].Restart(t) - select { - case ka, ok := <-rc: - if ok { - t.Fatalf("unexpected keepalive %v", ka) + // some keep-alives may still be buffered; drain until close + timer := time.After(time.Duration(kresp.TTL) * time.Second) + for kresp != nil { + select { + case kresp = <-rc: + case <-timer: + t.Fatalf("keepalive channel did not close") } - case <-time.After(5 * time.Second): - t.Fatalf("keepalive channel did not close") } }