Skip to content

Commit 2af1a4c

Browse files
committed
kvserver: deflake TestRequestsOnLaggingReplica
The test expects that when partitioning Node 1 (asymmetrically), and when the leadership moves away to another node, that requests to the partitioned node would return a speculative lease. However, it seems possible to me that the node 1 might have not heard about the new leader, and hence not return a speculative lease. This commit waits (for asymmetric partition) for replica 1 to hear about the new leader before continuing. Fixes: #158698 Release note: None
1 parent d85842e commit 2af1a4c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/kv/kvserver/client_raft_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,9 @@ func TestRequestsOnLaggingReplica(t *testing.T) {
10861086
defer log.Scope(t).Close(t)
10871087
ctx := context.Background()
10881088

1089+
// Increase the verbosity of the test to help investigate failures.
1090+
testutils.SetVModule(t, "replica_range_lease=3,raft=4,replica_raft_quiesce=3,verify=2")
1091+
10891092
testutils.RunTrueAndFalse(t, "symmetric", func(t *testing.T, symmetric bool) {
10901093
st := cluster.MakeTestingClusterSettings()
10911094
kvserver.OverrideDefaultLeaseType(ctx, &st.SV, roachpb.LeaseLeader)
@@ -1219,6 +1222,21 @@ func TestRequestsOnLaggingReplica(t *testing.T) {
12191222
//
12201223
// NB: This relies on RejectLeaseOnLeaderUnknown being set to true.
12211224
log.KvExec.Infof(ctx, "test: sending request to partitioned replica")
1225+
1226+
if !symmetric {
1227+
// In asymmetric partition, wait for the partitioned node to learn about
1228+
// the new leader before continuing. We do this because we expect it to
1229+
// reply with a speculative lease below.
1230+
testutils.SucceedsSoon(t, func() error {
1231+
status := partitionedReplica.RaftStatus()
1232+
if status.Lead != 2 && status.Lead != 3 {
1233+
return errors.Errorf("partitioned replica doesn't know about new leader yet: lead=%d",
1234+
status.Lead)
1235+
}
1236+
return nil
1237+
})
1238+
}
1239+
12221240
getRequest := getArgs(key)
12231241
_, pErr := kv.SendWrapped(timeoutCtx, partitionedStoreSender, getRequest)
12241242
require.Error(t, pErr.GoError(), "unexpected success")

0 commit comments

Comments
 (0)