Skip to content

Commit

Permalink
tests: Migrate TestCtlV3LeaseRevoke.* to common
Browse files Browse the repository at this point in the history
  • Loading branch information
endocrimes committed Mar 18, 2022
1 parent ab33535 commit 87740f6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
61 changes: 61 additions & 0 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,64 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
})
}
}

func TestLeaseGrantRevoke(t *testing.T) {
testRunner.BeforeTest(t)

tcs := []struct {
name string
config config.ClusterConfig
}{
{
name: "NoTLS",
config: config.ClusterConfig{ClusterSize: 1},
},
{
name: "PeerTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
},
{
name: "PeerAutoTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
},
{
name: "ClientTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS},
},
{
name: "ClientAutoTLS",
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
clus := testRunner.NewCluster(t, tc.config)
defer clus.Close()
cc := clus.Client()

testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
leaseResp, err := cc.Grant(20)
require.NoError(t, err)

err = cc.Put("foo", "bar", config.PutOptions{LeaseID: leaseResp.ID})
require.NoError(t, err)

getResp, err := cc.Get("foo", config.GetOptions{})
require.NoError(t, err)
require.Equal(t, int64(1), getResp.Count)

_, err = cc.LeaseRevoke(leaseResp.ID)
require.NoError(t, err)

ttlResp, err := cc.TimeToLive(leaseResp.ID, config.LeaseOption{})
require.NoError(t, err)
require.Equal(t, int64(-1), ttlResp.TTL)

getResp, err = cc.Get("foo", config.GetOptions{})
require.NoError(t, err)
// Value should expire with the lease
require.Equal(t, int64(0), getResp.Count)
})
})
}
}
39 changes: 0 additions & 39 deletions tests/e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ func TestCtlV3LeaseKeepAlivePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigPeerTLS()))
}

func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoked) }
func TestCtlV3LeaseRevokeNoTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigNoTLS()))
}
func TestCtlV3LeaseRevokeClientTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigClientTLS()))
}
func TestCtlV3LeaseRevokeClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigClientAutoTLS()))
}
func TestCtlV3LeaseRevokePeerTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigPeerTLS()))
}

func leaseTestKeepAlive(cx ctlCtx) {
// put with TTL 10 seconds and keep-alive
leaseID, err := ctlV3LeaseGrant(cx, 10)
Expand All @@ -68,31 +54,6 @@ func leaseTestKeepAlive(cx ctlCtx) {
}
}

func leaseTestRevoked(cx ctlCtx) {
err := leaseTestRevoke(cx)
if err != nil {
cx.t.Fatalf("leaseTestRevoke: (%v)", err)
}
}

func leaseTestRevoke(cx ctlCtx) error {
// put with TTL 10 seconds and revoke
leaseID, err := ctlV3LeaseGrant(cx, 10)
if err != nil {
return fmt.Errorf("ctlV3LeaseGrant error (%v)", err)
}
if err := ctlV3Put(cx, "key", "val", leaseID); err != nil {
return fmt.Errorf("ctlV3Put error (%v)", err)
}
if err := ctlV3LeaseRevoke(cx, leaseID); err != nil {
return fmt.Errorf("ctlV3LeaseRevoke error (%v)", err)
}
if err := ctlV3Get(cx, []string{"key"}); err != nil { // expect no output
return fmt.Errorf("ctlV3Get error (%v)", err)
}
return nil
}

func ctlV3LeaseGrant(cx ctlCtx, ttl int) (string, error) {
cmdArgs := append(cx.PrefixArgs(), "lease", "grant", strconv.Itoa(ttl))
proc, err := e2e.SpawnCmd(cmdArgs, cx.envMap)
Expand Down

0 comments on commit 87740f6

Please sign in to comment.