Skip to content

Commit

Permalink
tests: make TestRemovingProgress stable (#8998)
Browse files Browse the repository at this point in the history
close #8992

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
lhy1024 and ti-chi-bot[bot] authored Jan 16, 2025
1 parent dd8df1a commit 2ae49cb
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/kvproto/pkg/pdpb"

"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/response"
"github.com/tikv/pd/pkg/utils/apiutil"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/typeutil"
Expand Down Expand Up @@ -798,6 +799,24 @@ func TestRemovingProgress(t *testing.T) {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores/progress?id=2", http.MethodGet, http.StatusNotFound)
re.Contains(string(output), "no progress found for the given store ID")

// wait that stores are up
testutil.Eventually(re, func() bool {
output = sendRequest(re, leader.GetAddr()+"/pd/api/v1/stores", http.MethodGet, http.StatusOK)
var storesInfo response.StoresInfo
if err := json.Unmarshal(output, &storesInfo); err != nil {
return false
}
if len(storesInfo.Stores) != 3 {
return false
}
for _, store := range storesInfo.Stores {
if store.Store.GetNodeState() != metapb.NodeState_Serving {
return false
}
}
return true
})

// remove store 1 and store 2
_ = sendRequest(re, leader.GetAddr()+"/pd/api/v1/store/1", http.MethodDelete, http.StatusOK)
_ = sendRequest(re, leader.GetAddr()+"/pd/api/v1/store/2", http.MethodDelete, http.StatusOK)
Expand Down Expand Up @@ -840,6 +859,9 @@ func TestRemovingProgress(t *testing.T) {

testutil.Eventually(re, func() bool {
// wait for cluster prepare
if leader.GetRaftCluster() == nil {
return false
}
if !leader.GetRaftCluster().IsPrepared() {
leader.GetRaftCluster().SetPrepared()
return false
Expand All @@ -866,7 +888,7 @@ func TestRemovingProgress(t *testing.T) {
}
// store 1: 40/10s = 4
// store 2: 20/10s = 2
// average speed = (2+4)/2 = 33
// average speed = (2+4)/2 = 3.0
if p.CurrentSpeed != 3.0 {
return false
}
Expand Down Expand Up @@ -1097,15 +1119,19 @@ func sendRequest(re *require.Assertions, url string, method string, statusCode i

testutil.Eventually(re, func() bool {
resp, err := tests.TestDialClient.Do(req)
re.NoError(err)
if err != nil {
return false
}
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)
if resp.StatusCode != statusCode {
return false
}
output, err = io.ReadAll(resp.Body)
re.NoError(err)
return true
Expand Down

0 comments on commit 2ae49cb

Please sign in to comment.