mirror of https://github.com/tikv/client-go.git
*: fix panic log when call RegionRequestSender.String method (#1260)
Signed-off-by: crazycs520 <crazycs520@gmail.com>
This commit is contained in:
parent
125a140034
commit
146a6329d8
|
|
@ -117,7 +117,10 @@ type RegionRequestSender struct {
|
|||
}
|
||||
|
||||
func (s *RegionRequestSender) String() string {
|
||||
return fmt.Sprintf("{rpcError:%v,replicaSelector: %v}", s.rpcError, s.replicaSelector.String())
|
||||
if s.replicaSelector == nil {
|
||||
return fmt.Sprintf("{rpcError:%v, replicaSelector: %v}", s.rpcError, s.replicaSelector)
|
||||
}
|
||||
return fmt.Sprintf("{rpcError:%v, replicaSelector: %v}", s.rpcError, s.replicaSelector.String())
|
||||
}
|
||||
|
||||
// RegionRequestRuntimeStats records the runtime stats of send region requests.
|
||||
|
|
|
|||
|
|
@ -818,3 +818,13 @@ func (s *testRegionRequestToSingleStoreSuite) TestClientExt() {
|
|||
s.NotNil(sender.client)
|
||||
s.Nil(sender.getClientExt())
|
||||
}
|
||||
|
||||
func (s *testRegionRequestToSingleStoreSuite) TestRegionRequestSenderString() {
|
||||
sender := NewRegionRequestSender(s.cache, &fnClient{})
|
||||
loc, err := s.cache.LocateRegionByID(s.bo, s.region)
|
||||
s.Nil(err)
|
||||
// invalid region cache before sending request.
|
||||
s.cache.InvalidateCachedRegion(loc.Region)
|
||||
sender.SendReqCtx(s.bo, tikvrpc.NewRequest(tikvrpc.CmdGet, &kvrpcpb.GetRequest{}), loc.Region, time.Second, tikvrpc.TiKV)
|
||||
s.Equal("{rpcError:cached region invalid, replicaSelector: <nil>}", sender.String())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue