Skip to content

Commit

Permalink
test: make TestPreparingProgress stable (tikv#8966)
Browse files Browse the repository at this point in the history
close tikv#8693

Signed-off-by: okJiang <819421878@qq.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
okJiang and ti-chi-bot[bot] authored Jan 2, 2025
1 parent 7a30ebc commit 41919ad
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,13 +1092,24 @@ func TestPreparingProgress(t *testing.T) {
re.NoError(failpoint.Disable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs"))
}

func sendRequest(re *require.Assertions, url string, method string, statusCode int) []byte {
func sendRequest(re *require.Assertions, url string, method string, statusCode int) (output []byte) {
req, _ := http.NewRequest(method, url, http.NoBody)
resp, err := tests.TestDialClient.Do(req)
re.NoError(err)
re.Equal(statusCode, resp.StatusCode)
output, err := io.ReadAll(resp.Body)
re.NoError(err)
resp.Body.Close()

testutil.Eventually(re, func() bool {
resp, err := tests.TestDialClient.Do(req)
re.NoError(err)
defer resp.Body.Close()

// Due to service unavailability caused by environmental issues,
// we will retry it.
if resp.StatusCode == http.StatusServiceUnavailable {
return false
}
re.Equal(statusCode, resp.StatusCode)
output, err = io.ReadAll(resp.Body)
re.NoError(err)
return true
})

return output
}

0 comments on commit 41919ad

Please sign in to comment.