Skip to content

Commit

Permalink
integration: test lease list
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Aug 2, 2017
1 parent b33690e commit 959ebc0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
31 changes: 31 additions & 0 deletions clientv3/integration/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,37 @@ func TestLeaseTimeToLiveLeaseNotFound(t *testing.T) {
}
}

func TestLeaseList(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.List(context.Background())
if err != nil {
t.Fatal(err)
}
if len(resp.LeaseItems) != 5 {
t.Fatalf("len(resp.LeaseItems) expected 5, got %d", len(resp.LeaseItems))
}
for i := range resp.LeaseItems {
if ids[i] != resp.LeaseItems[i].ID {
t.Fatalf("#%d: lease ID expected %d, got %d", i, ids[i], resp.LeaseItems[i].ID)
}
}
}

// TestLeaseRenewLostQuorum ensures keepalives work after losing quorum
// for a while.
func TestLeaseRenewLostQuorum(t *testing.T) {
Expand Down
37 changes: 37 additions & 0 deletions integration/v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,43 @@ func TestV3LeaseExists(t *testing.T) {
}
}

// TestV3LeaseList creates leases and confirms list RPC fetches created ones.
func TestV3LeaseList(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.LeaseList(
context.Background(),
&pb.LeaseListRequest{})
if err != nil {
t.Fatal(err)
}
for i := range lresp.LeaseItems {
if lresp.LeaseItems[i].ID != ids[i] {
t.Fatalf("#%d: lease ID expected %d, got %d", i, ids[i], lresp.LeaseItems[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
Expand Down

0 comments on commit 959ebc0

Please sign in to comment.