Skip to content

Commit 5af8363

Browse files
committed
kvserver: deflake TestRefreshPolicyWithVariousLatencies
TestRefreshPolicyWithVariousLatencies verifies RefreshPolicy logic using a test latencies map. It was previously flaky due to: 1. not waiting for SetSpanConfig to take effect before invoking RefreshPolicy, which could trigger the background policy refresher during the test, and 2. background RefreshPolicy calls on leaseholder replicas interfering with the test. This commit resolves both issues by: 1. using SucceedsSoon to wait for SetSpanConfig to take effect, and 2. invoking RefreshPolicy on a non-leaseholder replica instead. Epic: none Release note: none
1 parent 6470faf commit 5af8363

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/kv/kvserver/replica_closedts_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,16 +1119,30 @@ func TestRefreshPolicyWithVariousLatencies(t *testing.T) {
11191119
defer log.Scope(t).Close(t)
11201120

11211121
ctx := context.Background()
1122-
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{})
1122+
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
1123+
ReplicationMode: base.ReplicationManual,
1124+
})
11231125
defer tc.Stopper().Stop(ctx)
11241126

11251127
// Create a scratch range.
11261128
scratchKey := tc.ScratchRange(t)
1127-
store := tc.GetFirstStoreFromServer(t, 0)
1129+
tc.AddVotersOrFatal(t, scratchKey, tc.Targets(1, 2)...)
1130+
1131+
// Get a non-leaseholder replica to avoid background RefreshPolicy calls that
1132+
// would interfere with testing the policy refresh logic in isolation.
1133+
store := tc.GetFirstStoreFromServer(t, 1)
11281134
repl := store.LookupReplica(roachpb.RKey(scratchKey))
11291135
require.NotNil(t, repl)
11301136
repl.SetSpanConfig(roachpb.SpanConfig{GlobalReads: true}, roachpb.Span{Key: scratchKey})
11311137

1138+
// Verify that the range is properly configured to use global reads.
1139+
testutils.SucceedsSoon(t, func() error {
1140+
if repl.GetRangeInfo(ctx).ClosedTimestampPolicy != roachpb.LEAD_FOR_GLOBAL_READS {
1141+
return errors.New("expected LEAD_FOR_GLOBAL_READS")
1142+
}
1143+
return nil
1144+
})
1145+
11321146
// Define test cases with different latency scenarios.
11331147
testCases := []struct {
11341148
name string

0 commit comments

Comments
 (0)