Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Jul 26, 2023
1 parent e660453 commit d5782d1
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,32 +249,6 @@ func (suite *regionTestSuite) TestRegions() {
}
}

func (suite *regionTestSuite) TestRegionsWithKillRequest() {
regionCount := 200000
for i := 0; i < regionCount; i++ {
r := core.NewTestRegionInfo(uint64(i+2), 1,
[]byte(fmt.Sprintf("%09d", i)),
[]byte(fmt.Sprintf("%09d", i+1)),
core.SetApproximateKeys(10), core.SetApproximateSize(10))
mustRegionHeartbeat(suite.Require(), suite.svr, r)
}
url := fmt.Sprintf("%s/regions", suite.urlPrefix)
ctx, cancel := context.WithCancel(context.Background())
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, bytes.NewBuffer(nil))
suite.NoError(err)
respCh := make(chan *http.Response)
go func() {
resp, err := testDialClient.Do(req) // nolint:bodyclose
suite.Error(err)
suite.Contains(err.Error(), "context canceled")
respCh <- resp
}()
time.Sleep(200 * time.Millisecond) // wait for the request to be sent
cancel() // close the request
resp := <-respCh
suite.Nil(resp)
}

func (suite *regionTestSuite) TestStoreRegions() {
re := suite.Require()
r1 := core.NewTestRegionInfo(2, 1, []byte("a"), []byte("b"))
Expand Down Expand Up @@ -481,6 +455,40 @@ func (suite *regionTestSuite) TestTopN() {
}
}

func TestRegionsWithKillRequest(t *testing.T) {
re := require.New(t)
svr, cleanup := mustNewServer(re)
defer cleanup()
server.MustWaitLeader(re, []*server.Server{svr})

addr := svr.GetAddr()
url := fmt.Sprintf("%s%s/api/v1/regions", addr, apiPrefix)
mustBootstrapCluster(re, svr)
regionCount := 200000
for i := 0; i < regionCount; i++ {
r := core.NewTestRegionInfo(uint64(i+2), 1,
[]byte(fmt.Sprintf("%09d", i)),
[]byte(fmt.Sprintf("%09d", i+1)),
core.SetApproximateKeys(10), core.SetApproximateSize(10))
mustRegionHeartbeat(re, svr, r)
}

ctx, cancel := context.WithCancel(context.Background())
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, bytes.NewBuffer(nil))
re.NoError(err)
respCh := make(chan *http.Response)
go func() {
resp, err := testDialClient.Do(req) // nolint:bodyclose
re.Error(err)
re.Contains(err.Error(), "context canceled")
respCh <- resp
}()
time.Sleep(200 * time.Millisecond) // wait for the request to be sent
cancel() // close the request
resp := <-respCh
re.Nil(resp)
}

type getRegionTestSuite struct {
suite.Suite
svr *server.Server
Expand Down

0 comments on commit d5782d1

Please sign in to comment.