From 5ebd7b0174eca883159ff5abf7c8dc68a37de973 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 1 Feb 2016 16:31:21 -0800 Subject: [PATCH] clientv3/integration: test on lease close --- clientv3/integration/lease_test.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go index 96e7d6326416..62e803cd3740 100644 --- a/clientv3/integration/lease_test.go +++ b/clientv3/integration/lease_test.go @@ -102,7 +102,6 @@ func TestLeaseKeepAlive(t *testing.T) { defer clus.Terminate(t) lapi := clientv3.NewLease(clus.RandClient()) - defer lapi.Close() resp, err := lapi.Create(context.Background(), 10) if err != nil { @@ -114,10 +113,21 @@ func TestLeaseKeepAlive(t *testing.T) { t.Errorf("failed to keepalive lease %v", kerr) } - kresp := <-rc + kresp, ok := <-rc + if !ok { + t.Errorf("chan is closed, want not closed") + } + if kresp.ID != resp.ID { t.Errorf("ID = %x, want %x", kresp.ID, resp.ID) } + + lapi.Close() + + _, ok = <-rc + if ok { + t.Errorf("chan is not closed, want lease Close() closes chan") + } } // TODO: add a client that can connect to all the members of cluster via unix sock. @@ -132,7 +142,6 @@ func TestLeaseKeepAliveHandleFailure(t *testing.T) { // TODO: change this line to get a cluster client lapi := clientv3.NewLease(clus.RandClient()) - defer lapi.Close() resp, err := lapi.Create(context.Background(), 10) if err != nil { @@ -165,4 +174,11 @@ func TestLeaseKeepAliveHandleFailure(t *testing.T) { if kresp.ID != resp.ID { t.Errorf("ID = %x, want %x", kresp.ID, resp.ID) } + + lapi.Close() + + _, ok = <-rc + if ok { + t.Errorf("chan is not closed, want lease Close() closes chan") + } }