From 41919ad57acca17c6e2c24a19a1c0185c355e469 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 2 Jan 2025 16:46:51 +0800 Subject: [PATCH] test: make TestPreparingProgress stable (#8966) close tikv/pd#8693 Signed-off-by: okJiang <819421878@qq.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- tests/server/api/api_test.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index faa22ce08f4..44a0ae69a46 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -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 }