tests: migrate TestCtlV3LeaseKeepAliveOnce.* to common

This commit is contained in:
Danielle Lancashire 2022-03-16 16:00:44 +00:00
parent 353b011f59
commit 36279e0797
2 changed files with 52 additions and 45 deletions

View File

@ -207,3 +207,55 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
})
}
}
func TestLeaseGrantKeepAliveOnce(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(2)
require.NoError(t, err)
_, err = cc.LeaseKeepAliveOnce(leaseResp.ID)
require.NoError(t, err)
time.Sleep(2 * time.Second) // Wait for the original lease to expire
ttlResp, err := cc.TimeToLive(leaseResp.ID, config.LeaseOption{})
require.NoError(t, err)
// We still have a lease!
require.Greater(t, int64(2), ttlResp.TTL)
})
})
}
}

View File

@ -37,20 +37,6 @@ func TestCtlV3LeaseKeepAlivePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAlive, withCfg(*e2e.NewConfigPeerTLS()))
}
func TestCtlV3LeaseKeepAliveOnce(t *testing.T) { testCtl(t, leaseTestKeepAliveOnce) }
func TestCtlV3LeaseKeepAliveOnceNoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(*e2e.NewConfigNoTLS()))
}
func TestCtlV3LeaseKeepAliveOnceClientTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(*e2e.NewConfigClientTLS()))
}
func TestCtlV3LeaseKeepAliveOnceClientAutoTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(*e2e.NewConfigClientAutoTLS()))
}
func TestCtlV3LeaseKeepAliveOncePeerTLS(t *testing.T) {
testCtl(t, leaseTestKeepAliveOnce, withCfg(*e2e.NewConfigPeerTLS()))
}
func TestCtlV3LeaseRevoke(t *testing.T) { testCtl(t, leaseTestRevoked) }
func TestCtlV3LeaseRevokeNoTLS(t *testing.T) {
testCtl(t, leaseTestRevoked, withCfg(*e2e.NewConfigNoTLS()))
@ -82,23 +68,6 @@ func leaseTestKeepAlive(cx ctlCtx) {
}
}
func leaseTestKeepAliveOnce(cx ctlCtx) {
// put with TTL 10 seconds and keep-alive once
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 := ctlV3LeaseKeepAliveOnce(cx, leaseID); err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3LeaseKeepAliveOnce error (%v)", err)
}
if err := ctlV3Get(cx, []string{"key"}, kv{"key", "val"}); err != nil {
cx.t.Fatalf("leaseTestKeepAlive: ctlV3Get error (%v)", err)
}
}
func leaseTestRevoked(cx ctlCtx) {
err := leaseTestRevoke(cx)
if err != nil {
@ -161,20 +130,6 @@ func ctlV3LeaseKeepAlive(cx ctlCtx, leaseID string) error {
return proc.Stop()
}
func ctlV3LeaseKeepAliveOnce(cx ctlCtx, leaseID string) error {
cmdArgs := append(cx.PrefixArgs(), "lease", "keep-alive", "--once", leaseID)
proc, err := e2e.SpawnCmd(cmdArgs, nil)
if err != nil {
return err
}
if _, err = proc.Expect(fmt.Sprintf("lease %s keepalived with TTL(", leaseID)); err != nil {
return err
}
return proc.Stop()
}
func ctlV3LeaseRevoke(cx ctlCtx, leaseID string) error {
cmdArgs := append(cx.PrefixArgs(), "lease", "revoke", leaseID)
return e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, fmt.Sprintf("lease %s revoked", leaseID))