From c32e491389dd2b1912c4c47918b1682b389385b8 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Fri, 10 Feb 2017 16:25:46 -0800 Subject: [PATCH] clientv3/integration: test lease not found on TimeToLive() --- clientv3/integration/lease_test.go | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go index 851b1fedd8b3..707d827bc245 100644 --- a/clientv3/integration/lease_test.go +++ b/clientv3/integration/lease_test.go @@ -504,6 +504,42 @@ func TestLeaseTimeToLive(t *testing.T) { } } +func TestLeaseTimeToLiveLeaseNotFound(t *testing.T) { + defer testutil.AfterTest(t) + + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + cli := clus.RandClient() + resp, err := cli.Grant(context.Background(), 10) + if err != nil { + t.Errorf("failed to create lease %v", err) + } + _, err = cli.Revoke(context.Background(), resp.ID) + if err != nil { + t.Errorf("failed to Revoke lease %v", err) + } + + lresp, err := cli.TimeToLive(context.Background(), resp.ID) + // TimeToLive() doesn't return LeaseNotFound error + // but return a response with TTL to be 0 + if err != nil { + t.Fatalf("expected err to be nil") + } + if lresp == nil { + t.Fatalf("expected lresp not to be nil") + } + if lresp.ResponseHeader == nil { + t.Fatalf("expected ResponseHeader not to be nil") + } + if lresp.ID != resp.ID { + t.Fatalf("expected Lease ID %v, but got %v", resp.ID, lresp.ID) + } + if lresp.TTL != -1 { + t.Fatalf("expected TTL %v, but got %v", lresp.TTL, lresp.TTL) + } +} + // TestLeaseRenewLostQuorum ensures keepalives work after losing quorum // for a while. func TestLeaseRenewLostQuorum(t *testing.T) {