Skip to content

Commit e99f20a

Browse files
authored
Merge pull request #19504 from tcchawla/fix-19500
tests: deflakey TestLeaseGrantKeepAliveOnce
2 parents 3a2cece + 3e43e45 commit e99f20a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tests/common/lease_test.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
175175

176176
for _, tc := range clusterTestCases() {
177177
t.Run(tc.name, func(t *testing.T) {
178-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
178+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
179179
defer cancel()
180180
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
181181
defer clus.Close()
@@ -188,7 +188,23 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
188188
_, err = cc.KeepAliveOnce(ctx, leaseResp.ID)
189189
require.NoError(t, err)
190190

191-
time.Sleep(2 * time.Second) // Wait for the original lease to expire
191+
// FIXME: When leader changes, old leader steps
192+
// back to follower and ignores the lease revoking.
193+
// The new leader will restart TTL counting. If so,
194+
// we should call time.Sleep again and wait for revoking.
195+
// It can't avoid flakey but reduce flakey possiblility.
196+
for i := 0; i < 3; i++ {
197+
currentLeader := clus.WaitLeader(t)
198+
t.Logf("[%d] current leader index %d", i, currentLeader)
199+
200+
time.Sleep(2 * time.Second)
201+
202+
newLeader := clus.WaitLeader(t)
203+
if newLeader == currentLeader {
204+
break
205+
}
206+
t.Logf("[%d] leader changed, new leader index %d", i, newLeader)
207+
}
192208

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

0 commit comments

Comments
 (0)