Skip to content

Commit

Permalink
test/server: replace default 30s to 1s to reduce test cost time (tikv…
Browse files Browse the repository at this point in the history
…#8171)

ref tikv#7969

Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp authored May 14, 2024
1 parent 5f8c38b commit ba7e63a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ func (suite *middlewareTestSuite) TestRequestInfoMiddleware() {
labels := make(map[string]any)
labels["testkey"] = "testvalue"
data, _ = json.Marshal(labels)
resp, err = dialClient.Post(leader.GetAddr()+"/pd/api/v1/debug/pprof/profile?force=true", "application/json", bytes.NewBuffer(data))
resp, err = dialClient.Post(leader.GetAddr()+"/pd/api/v1/debug/pprof/profile?seconds=1", "application/json", bytes.NewBuffer(data))
re.NoError(err)
_, err = io.ReadAll(resp.Body)
resp.Body.Close()
re.NoError(err)
re.Equal(http.StatusOK, resp.StatusCode)

re.Equal("Profile", resp.Header.Get("service-label"))
re.Equal("{\"force\":[\"true\"]}", resp.Header.Get("url-param"))
re.Equal("{\"seconds\":[\"1\"]}", resp.Header.Get("url-param"))
re.Equal("{\"testkey\":\"testvalue\"}", resp.Header.Get("body-param"))
re.Equal("HTTP/1.1/POST:/pd/api/v1/debug/pprof/profile", resp.Header.Get("method"))
re.Equal("anonymous", resp.Header.Get("caller-id"))
Expand All @@ -182,7 +182,7 @@ func (suite *middlewareTestSuite) TestRequestInfoMiddleware() {
re.False(leader.GetServer().GetServiceMiddlewarePersistOptions().IsAuditEnabled())

header := mustRequestSuccess(re, leader.GetServer())
re.Equal("", header.Get("service-label"))
re.Equal("GetVersion", header.Get("service-label"))

re.NoError(failpoint.Disable("github.com/tikv/pd/server/api/addRequestInfoMiddleware"))
}
Expand Down Expand Up @@ -373,6 +373,18 @@ func (suite *middlewareTestSuite) TestRateLimitMiddleware() {
re.NoError(err)
re.Equal(http.StatusOK, resp.StatusCode)
}

// reset rate limit
input = map[string]any{
"enable-rate-limit": "true",
}
data, err = json.Marshal(input)
re.NoError(err)
req, _ = http.NewRequest(http.MethodPost, leader.GetAddr()+"/pd/api/v1/service-middleware/config", bytes.NewBuffer(data))
resp, err = dialClient.Do(req)
re.NoError(err)
resp.Body.Close()
re.True(leader.GetServer().GetServiceMiddlewarePersistOptions().IsRateLimitEnabled())
}

func (suite *middlewareTestSuite) TestSwaggerUrl() {
Expand Down

0 comments on commit ba7e63a

Please sign in to comment.