From bf51b33bf88f917a288eff6d5da9dd4ae29767e4 Mon Sep 17 00:00:00 2001 From: lysu Date: Wed, 31 Jul 2019 17:18:40 +0800 Subject: [PATCH] tikv: make region_request_test stable (#11541) # Conflicts: # store/tikv/region_request_test.go --- store/tikv/region_request_test.go | 39 +++++++++++++------------------ 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/store/tikv/region_request_test.go b/store/tikv/region_request_test.go index c9de5927b79ee..9cf0203647d98 100644 --- a/store/tikv/region_request_test.go +++ b/store/tikv/region_request_test.go @@ -100,40 +100,33 @@ func (s *testRegionRequestSuite) TestOnSendFailedWithCloseKnownStoreThenUseNewOn Value: []byte("value"), }, } - region, err := s.cache.LocateRegionByID(s.bo, s.region) - c.Assert(err, IsNil) - c.Assert(region, NotNil) - resp, err := s.regionRequestSender.SendReq(s.bo, req, region.Region, time.Second) - c.Assert(err, IsNil) - c.Assert(resp.RawPut, NotNil) - // add new unknown region + // add new store2 and make store2 as leader. store2 := s.cluster.AllocID() peer2 := s.cluster.AllocID() s.cluster.AddStore(store2, fmt.Sprintf("store%d", store2)) - s.cluster.AddPeer(region.Region.id, store2, peer2) - - // stop known region - s.cluster.StopStore(s.store) + s.cluster.AddPeer(s.region, store2, peer2) + s.cluster.ChangeLeader(s.region, peer2) - // send to failed store - resp, err = s.regionRequestSender.SendReq(NewBackoffer(context.Background(), 100), req, region.Region, time.Second) - c.Assert(err, IsNil) - regionErr, err := resp.GetRegionError() + region, err := s.cache.LocateRegionByID(s.bo, s.region) c.Assert(err, IsNil) - c.Assert(regionErr, NotNil) - - // retry to send store by old region info - region, err = s.cache.LocateRegionByID(s.bo, s.region) c.Assert(region, NotNil) + resp, err := s.regionRequestSender.SendReq(s.bo, req, region.Region, time.Second) c.Assert(err, IsNil) + c.Assert(resp.RawPut, NotNil) + + // stop store2 and make store1 as new leader. + s.cluster.StopStore(store2) + s.cluster.ChangeLeader(s.region, s.peer) - // retry again, reload region info and send to new store. - resp, err = s.regionRequestSender.SendReq(NewBackoffer(context.Background(), 100), req, region.Region, time.Second) + // send to store2 fail and send to new leader store1. + bo2 := NewBackoffer(context.Background(), 100) + resp, err = s.regionRequestSender.SendReq(bo2, req, region.Region, time.Second) c.Assert(err, IsNil) - regionErr, err = resp.GetRegionError() + regionErr, err := resp.GetRegionError() c.Assert(err, IsNil) - c.Assert(regionErr, NotNil) + c.Assert(regionErr, IsNil) + c.Assert(resp.RawPut, NotNil) } func (s *testRegionRequestSuite) TestSendReqCtx(c *C) {