From 556c1a1fe0a13757de796db4e5f33931a990627c Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Mon, 14 Aug 2017 11:31:15 -0700 Subject: [PATCH] integration,clientv3/integration: test LeaseLeases API Signed-off-by: Gyu-Ho Lee --- clientv3/integration/lease_test.go | 31 +++++++++++++++++++++++++ integration/v3_lease_test.go | 37 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go index 8bdb0ff3f34..ec59cf62530 100644 --- a/clientv3/integration/lease_test.go +++ b/clientv3/integration/lease_test.go @@ -574,6 +574,37 @@ func TestLeaseTimeToLiveLeaseNotFound(t *testing.T) { } } +func TestLeaseLeases(t *testing.T) { + defer testutil.AfterTest(t) + + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + cli := clus.RandClient() + + ids := []clientv3.LeaseID{} + for i := 0; i < 5; i++ { + resp, err := cli.Grant(context.Background(), 10) + if err != nil { + t.Errorf("failed to create lease %v", err) + } + ids = append(ids, resp.ID) + } + + resp, err := cli.Leases(context.Background()) + if err != nil { + t.Fatal(err) + } + if len(resp.Leases) != 5 { + t.Fatalf("len(resp.Leases) expected 5, got %d", len(resp.Leases)) + } + for i := range resp.Leases { + if ids[i] != resp.Leases[i].ID { + t.Fatalf("#%d: lease ID expected %d, got %d", i, ids[i], resp.Leases[i].ID) + } + } +} + // TestLeaseRenewLostQuorum ensures keepalives work after losing quorum // for a while. func TestLeaseRenewLostQuorum(t *testing.T) { diff --git a/integration/v3_lease_test.go b/integration/v3_lease_test.go index 7bb72ba131f..7ea873f86bf 100644 --- a/integration/v3_lease_test.go +++ b/integration/v3_lease_test.go @@ -234,6 +234,43 @@ func TestV3LeaseExists(t *testing.T) { } } +// TestV3LeaseLeases creates leases and confirms list RPC fetches created ones. +func TestV3LeaseLeases(t *testing.T) { + defer testutil.AfterTest(t) + clus := NewClusterV3(t, &ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + ctx0, cancel0 := context.WithCancel(context.Background()) + defer cancel0() + + // create leases + ids := []int64{} + for i := 0; i < 5; i++ { + lresp, err := toGRPC(clus.RandClient()).Lease.LeaseGrant( + ctx0, + &pb.LeaseGrantRequest{TTL: 30}) + if err != nil { + t.Fatal(err) + } + if lresp.Error != "" { + t.Fatal(lresp.Error) + } + ids = append(ids, lresp.ID) + } + + lresp, err := toGRPC(clus.RandClient()).Lease.LeaseLeases( + context.Background(), + &pb.LeaseLeasesRequest{}) + if err != nil { + t.Fatal(err) + } + for i := range lresp.Leases { + if lresp.Leases[i].ID != ids[i] { + t.Fatalf("#%d: lease ID expected %d, got %d", i, ids[i], lresp.Leases[i].ID) + } + } +} + // TestV3LeaseRenewStress keeps creating lease and renewing it immediately to ensure the renewal goes through. // it was oberserved that the immediate lease renewal after granting a lease from follower resulted lease not found. // related issue https://github.com/coreos/etcd/issues/6978