Skip to content

Commit

Permalink
reproduce 16845
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Oct 27, 2023
1 parent 5fad87c commit cd4df45
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions tests/e2e/ctl_v3_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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)
})
}
2 changes: 1 addition & 1 deletion tests/e2e/http_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cd4df45

Please sign in to comment.