Skip to content

Commit

Permalink
e2e: improve lease coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hexfusion committed Dec 15, 2017
1 parent b48cf77 commit 9b6cd03
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 5 deletions.
62 changes: 62 additions & 0 deletions e2e/ctl_v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package e2e
import (
"fmt"
"os"
"strings"
"testing"
"time"

"github.com/coreos/etcd/clientv3"
)
Expand All @@ -41,6 +43,9 @@ func TestCtlV3AuthInvalidMgmt(t *testing.T) { testCtl(t, authTestInvalidMgm
func TestCtlV3AuthFromKeyPerm(t *testing.T) { testCtl(t, authTestFromKeyPerm) }
func TestCtlV3AuthAndWatch(t *testing.T) { testCtl(t, authTestWatch) }

func TestCtlV3AuthLeaseTestKeepAlive(t *testing.T) { testCtl(t, authLeaseTestKeepAlive) }
func TestCtlV3AuthLeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, authLeaseTestTimeToLiveExpired) }

func TestCtlV3AuthRoleGet(t *testing.T) { testCtl(t, authTestRoleGet) }
func TestCtlV3AuthUserGet(t *testing.T) { testCtl(t, authTestUserGet) }
func TestCtlV3AuthRoleList(t *testing.T) { testCtl(t, authTestRoleList) }
Expand Down Expand Up @@ -723,6 +728,63 @@ func authTestFromKeyPerm(cx ctlCtx) {
}
}

func authLeaseTestKeepAlive(cx ctlCtx) {
if err := authEnable(cx); err != nil {
cx.t.Fatal(err)
}

cx.user, cx.pass = "root", "root"
authSetupTestUser(cx)
// put with TTL 10 seconds and keep-alive
leaseID, err := ctlV3LeaseGrant(cx, 10)
if err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3LeaseGrant error (%v)", err)
}
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3Put error (%v)", err)
}
if err := ctlV3LeaseKeepAlive(cx, leaseID); err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3LeaseKeepAlive error (%v)", err)
}
if err := ctlV3Get(cx, []string{"key"}, kv{"key", "val"}); err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3Get error (%v)", err)
}
}

func authLeaseTestTimeToLiveExpired(cx ctlCtx) {
if err := authEnable(cx); err != nil {
cx.t.Fatal(err)
}

cx.user, cx.pass = "root", "root"
authSetupTestUser(cx)

leaseID, err := ctlV3LeaseGrant(cx, 3)
if err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
cx.t.Fatalf("authLeaseTestTimeToLiveExpired: ctlV3Put error (%v)", err)
}
// eliminate false posative
time.Sleep(3 * time.Second)
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", leaseID)
proc, err := spawnCmd(cmdArgs)
if err != nil {
cx.t.Fatal(err)
}
line, err := proc.Expect(" granted with TTL(")
if err != nil {
cx.t.Fatal(err)
}
if !strings.Contains(line, "TTL(3s), remaining(0s)") {
cx.t.Fatalf("expected 'TTL(3s), remaining(0s)', got %q", line)
}
if err := ctlV3Get(cx, []string{"key"}, kv{"key", ""}); err != nil {
cx.t.Fatalf("authLeaseTestTimeToLiveExpired: ctlV3Get error (%v)", err)
}
}

func authTestWatch(cx ctlCtx) {
if err := authEnable(cx); err != nil {
cx.t.Fatal(err)
Expand Down
39 changes: 34 additions & 5 deletions e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import (
"strconv"
"strings"
"testing"
"time"
)

func TestCtlV3LeaseGrantTimeToLive(t *testing.T) { testCtl(t, leaseTestGrantTimeToLive) }
func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeasesList) }
func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) }
func TestCtlV3LeaseKeepAliveOnce(t *testing.T) { testCtl(t, leaseTestKeepAliveOnce) }
func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoke) }
func TestCtlV3LeaseGrantTimeToLive(t *testing.T) { testCtl(t, leaseTestGrantTimeToLive) }
func TestCtlV3LeaseGrantLeases(t *testing.T) { testCtl(t, leaseTestGrantLeasesList) }
func TestCtlV3LeaseTestTimeToLiveExpired(t *testing.T) { testCtl(t, leaseTestTimeToLiveExpired) }
func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) }
func TestCtlV3LeaseKeepAliveOnce(t *testing.T) { testCtl(t, leaseTestKeepAliveOnce) }
func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoke) }

func leaseTestGrantTimeToLive(cx ctlCtx) {
id, err := ctlV3LeaseGrant(cx, 10)
Expand Down Expand Up @@ -73,6 +75,33 @@ func leaseTestGrantLeasesList(cx ctlCtx) {
}
}

func leaseTestTimeToLiveExpired(cx ctlCtx) {
leaseID, err := ctlV3LeaseGrant(cx, 3)
if err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
cx.t.Fatalf("leaseTestTimeToLiveExpired: ctlV3Put error (%v)", err)
}
// eliminate false posative
time.Sleep(3 * time.Second)
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", leaseID)
proc, err := spawnCmd(cmdArgs)
if err != nil {
cx.t.Fatal(err)
}
line, err := proc.Expect(" granted with TTL(")
if err != nil {
cx.t.Fatal(err)
}
if !strings.Contains(line, "TTL(3s), remaining(0s)") {
cx.t.Fatalf("expected 'TTL(3s), remaining(0s)', got %q", line)
}
if err := ctlV3Get(cx, []string{"key"}, kv{"key", ""}); err != nil {
cx.t.Fatalf("leaseTestTimeToLiveExpired: ctlV3Get error (%v)", err)
}
}

func leaseTestKeepAlive(cx ctlCtx) {
// put with TTL 10 seconds and keep-alive
leaseID, err := ctlV3LeaseGrant(cx, 10)
Expand Down

0 comments on commit 9b6cd03

Please sign in to comment.