Skip to content

Commit

Permalink
Merge pull request etcd-io#19476 from fuweid/fix-17504
Browse files Browse the repository at this point in the history
tests: deflakey TestLeaseGrantTimeToLiveExpired
  • Loading branch information
ahrtr authored Feb 25, 2025
2 parents 6d66d82 + c81fb87 commit 8e44d3a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {

for _, tc := range clusterTestCases() {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
Expand All @@ -139,7 +139,23 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
require.NoError(t, err)
require.Equal(t, int64(1), getResp.Count)

time.Sleep(3 * time.Second)
// FIXME: When leader changes, old leader steps
// back to follower and ignores the lease revoking.
// The new leader will restart TTL counting. If so,
// we should call time.Sleep again and wait for revoking.
// It can't avoid flakey but reduce flakey possiblility.
for i := 0; i < 3; i++ {
currentLeader := clus.WaitLeader(t)
t.Logf("[%d] current leader index %d", i, currentLeader)

time.Sleep(3 * time.Second)

newLeader := clus.WaitLeader(t)
if newLeader == currentLeader {
break
}
t.Logf("[%d] leader changed, new leader index %d", i, newLeader)
}

ttlResp, err := cc.TimeToLive(ctx, leaseResp.ID, config.LeaseOption{})
require.NoError(t, err)
Expand Down

0 comments on commit 8e44d3a

Please sign in to comment.