From cd4df45b9722d8a7c67156936c9e22a3020dc014 Mon Sep 17 00:00:00 2001 From: Chao Chen Date: Fri, 27 Oct 2023 16:27:12 -0700 Subject: [PATCH] reproduce 16845 Signed-off-by: Chao Chen --- tests/e2e/ctl_v3_lease_test.go | 42 +++++++++++++++++++++++++++++ tests/e2e/http_health_check_test.go | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/e2e/ctl_v3_lease_test.go b/tests/e2e/ctl_v3_lease_test.go index e556798745f..a9c9a4f1e20 100644 --- a/tests/e2e/ctl_v3_lease_test.go +++ b/tests/e2e/ctl_v3_lease_test.go @@ -15,13 +15,19 @@ package e2e import ( + "context" "fmt" "strconv" "strings" "testing" + "time" + + "github.com/stretchr/testify/require" "go.etcd.io/etcd/pkg/v3/expect" + "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" + "go.etcd.io/etcd/tests/v3/framework/testutils" ) func TestCtlV3LeaseKeepAlive(t *testing.T) { testCtl(t, leaseTestKeepAlive) } @@ -96,3 +102,39 @@ func ctlV3LeaseRevoke(cx ctlCtx, leaseID string) error { cmdArgs := append(cx.PrefixArgs(), "lease", "revoke", leaseID) return e2e.SpawnWithExpectWithEnv(cmdArgs, cx.envMap, expect.ExpectedResponse{Value: fmt.Sprintf("lease %s revoked", leaseID)}) } + +func TestLeaseGrantTimeToLiveExpired(t *testing.T) { + e2e.BeforeTest(t) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + clus, cerr := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithClusterSize(1), e2e.WithGoFailEnabled(true)) + require.NoError(t, cerr) + defer clus.Close() + + testutils.ExecuteUntil(ctx, t, func() { + cc := clus.Etcdctl() + leaseResp, err := cc.Grant(ctx, 2) + require.NoError(t, err) + + err = cc.Put(ctx, "foo", "bar", config.PutOptions{LeaseID: leaseResp.ID}) + require.NoError(t, err) + + getResp, err := cc.Get(ctx, "foo", config.GetOptions{}) + require.NoError(t, err) + require.Equal(t, int64(1), getResp.Count) + + triggerRaftLoopDeadLock(ctx, t, clus) + + time.Sleep(3 * time.Second) + + ttlResp, err := cc.TimeToLive(ctx, leaseResp.ID, config.LeaseOption{}) + require.NoError(t, err) + require.Equal(t, int64(-1), ttlResp.TTL) + + getResp, err = cc.Get(ctx, "foo", config.GetOptions{}) + require.NoError(t, err) + // Value should expire with the lease + require.Equal(t, int64(0), getResp.Count) + }) +} diff --git a/tests/e2e/http_health_check_test.go b/tests/e2e/http_health_check_test.go index 8007b48f634..9a5534c32c1 100644 --- a/tests/e2e/http_health_check_test.go +++ b/tests/e2e/http_health_check_test.go @@ -210,7 +210,7 @@ func blackhole(_ context.Context, t *testing.T, clus *e2e.EtcdProcessCluster) { func triggerRaftLoopDeadLock(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster) { require.NoError(t, clus.Procs[0].Failpoints().SetupHTTP(ctx, "raftBeforeSave", `sleep("3s")`)) - clus.Procs[0].Etcdctl().Put(context.Background(), "foo", "bar", config.PutOptions{}) + clus.Procs[0].Etcdctl().Put(context.Background(), "foo", "bar", config.PutOptions{Timeout: 100 * time.Millisecond}) } func triggerSlowBufferWriteBackWithAuth(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster) {