Skip to content

Commit

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

"github.com/coreos/etcd/clientv3"
)
Expand Down Expand Up @@ -759,30 +757,10 @@ func authLeaseTestTimeToLiveExpired(cx ctlCtx) {
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 {
ttl := 3
if err := leaseTestTimeToLiveExpire(cx, ttl); 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) {
Expand Down
31 changes: 23 additions & 8 deletions e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,45 @@ func leaseTestGrantLeasesList(cx ctlCtx) {
}

func leaseTestTimeToLiveExpired(cx ctlCtx) {
leaseID, err := ctlV3LeaseGrant(cx, 3)
err := leaseTestTimeToLiveExpire(cx, 3)
if err != nil {
cx.t.Fatal(err)
}
}

func leaseTestTimeToLiveExpire(cx ctlCtx, ttl int) error {
leaseID, err := ctlV3LeaseGrant(cx, ttl)
if err != nil {
return err
}

// using auth?
r := 0
if cx.pass != "" {
r = -1
}
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)
// eliminate false positive
time.Sleep(time.Duration(ttl+1) * time.Second)
cmdArgs := append(cx.PrefixArgs(), "lease", "timetolive", leaseID)
proc, err := spawnCmd(cmdArgs)
if err != nil {
cx.t.Fatal(err)
return err
}
line, err := proc.Expect(" granted with TTL(")
if err != nil {
cx.t.Fatal(err)
return err
}
if !strings.Contains(line, "TTL(3s), remaining(0s)") {
cx.t.Fatalf("expected 'TTL(3s), remaining(0s)', got %q", line)
e := fmt.Sprintf("TTL(3s), remaining(%ds)", r)
if !strings.Contains(line, e) {
return fmt.Errorf(fmt.Sprintf("expected '%s', got %q", e, line))
}
if err := ctlV3Get(cx, []string{"key"}, kv{"key", ""}); err != nil {
cx.t.Fatalf("leaseTestTimeToLiveExpired: ctlV3Get error (%v)", err)
fmt.Errorf("leaseTestTimeToLiveExpired: ctlV3Get error (%v)", err)
}
return nil
}

func leaseTestKeepAlive(cx ctlCtx) {
Expand Down

0 comments on commit ee329c0

Please sign in to comment.