From 665dee5a969821ce020c630e7b51db60d0e15ef8 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 13 Nov 2024 16:37:24 +0800 Subject: [PATCH] fix TestPreparingProgress Signed-off-by: Ryan Leung --- tests/server/api/api_test.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index 828213587d6..e2c2ce879df 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -1008,28 +1008,15 @@ func TestPreparingProgress(t *testing.T) { for _, store := range stores[2:] { tests.MustPutStore(re, cluster, store) } - // no store preparing - output := sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?action=preparing", http.MethodGet, http.StatusNotFound) - re.Contains(string(output), "no progress found for the action") - output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=4", http.MethodGet, http.StatusNotFound) - re.Contains(string(output), "no progress found for the given store ID") if !leader.GetRaftCluster().IsPrepared() { testutil.Eventually(re, func() bool { if leader.GetRaftCluster().IsPrepared() { return true } - url := leader.GetAddr() + "/pd/api/v1/stores/progress?action=preparing" - req, _ := http.NewRequest(http.MethodGet, url, http.NoBody) - resp, err := tests.TestDialClient.Do(req) - re.NoError(err) - defer resp.Body.Close() - if resp.StatusCode != http.StatusNotFound { - return false - } - // is not prepared - output, err := io.ReadAll(resp.Body) - re.NoError(err) + + // no store preparing + output := sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?action=preparing", http.MethodGet, http.StatusNotFound) re.Contains(string(output), "no progress found for the action") output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=4", http.MethodGet, http.StatusNotFound) re.Contains(string(output), "no progress found for the given store ID") @@ -1092,7 +1079,7 @@ func TestPreparingProgress(t *testing.T) { return true }) - output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=4", http.MethodGet, http.StatusOK) + output := sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=4", http.MethodGet, http.StatusOK) re.NoError(json.Unmarshal(output, &p)) re.Equal("preparing", p.Action) re.Equal("0.05", fmt.Sprintf("%.2f", p.Progress))