From e1edb7c4122deb15118dcdfacb904800137b49f9 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 8 Apr 2024 00:39:39 +0800 Subject: [PATCH] add prefer-leader test case Signed-off-by: crazycs520 --- internal/locate/replica_selector_test.go | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/internal/locate/replica_selector_test.go b/internal/locate/replica_selector_test.go index add7b7486..bdb8325b6 100644 --- a/internal/locate/replica_selector_test.go +++ b/internal/locate/replica_selector_test.go @@ -684,6 +684,47 @@ func TestReplicaReadAccessPathByCase(t *testing.T) { }, } s.True(s.runCaseAndCompare(ca)) + + ca = replicaSelectorAccessPathCase{ + reqType: tikvrpc.CmdGet, + readType: kv.ReplicaReadPreferLeader, + staleRead: false, + accessErr: []RegionErrorType{ServerIsBusyErr, ServerIsBusyErr, ServerIsBusyErr}, + expect: &accessPathResult{ + accessPath: []string{ + "{addr: store3, replica-read: true, stale-read: false}", + "{addr: store1, replica-read: true, stale-read: false}", + "{addr: store2, replica-read: true, stale-read: false}", + }, + respErr: "", + respRegionError: fakeEpochNotMatch, + backoffCnt: 1, + backoffDetail: []string{"tikvServerBusy+1"}, + regionIsValid: false, + }, + } + s.True(s.runCaseAndCompare(ca)) + + ca = replicaSelectorAccessPathCase{ + reqType: tikvrpc.CmdGet, + readType: kv.ReplicaReadPreferLeader, + staleRead: false, + label: &metapb.StoreLabel{Key: "id", Value: "2"}, + accessErr: []RegionErrorType{ServerIsBusyErr, ServerIsBusyErr, ServerIsBusyErr}, + expect: &accessPathResult{ + accessPath: []string{ + "{addr: store2, replica-read: true, stale-read: false}", + "{addr: store3, replica-read: true, stale-read: false}", + "{addr: store1, replica-read: true, stale-read: false}", + }, + respErr: "", + respRegionError: fakeEpochNotMatch, + backoffCnt: 1, + backoffDetail: []string{"tikvServerBusy+1"}, + regionIsValid: false, + }, + } + s.True(s.runCaseAndCompare(ca)) s.changeRegionLeader(1) }