Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tikv: make region_request_test stable #11541

Merged
merged 4 commits into from
Jul 31, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions store/tikv/region_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,33 @@ func (s *testRegionRequestSuite) TestOnSendFailedWithCloseKnownStoreThenUseNewOn
Key: []byte("key"),
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.Resp, 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.Resp, 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.Resp, NotNil)
}

func (s *testRegionRequestSuite) TestSendReqCtx(c *C) {
Expand Down