Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make TestPreparingProgress stable #8966

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions tests/server/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,11 +1094,26 @@ func TestPreparingProgress(t *testing.T) {

func sendRequest(re *require.Assertions, url string, method string, statusCode int) []byte {
req, _ := http.NewRequest(method, url, http.NoBody)
resp, err := tests.TestDialClient.Do(req)
re.NoError(err)
var (
err error
resp *http.Response
)
testutil.Eventually(re, func() bool {
//nolint:bodyclose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignore this lint? you can place defer resp.Body.Close() into this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is closed in L1108 already

resp, err = tests.TestDialClient.Do(req)
re.NoError(err)
// Due to service unavailability caused by environmental issues,
// we will retry it.
if resp.StatusCode == http.StatusServiceUnavailable {
resp.Body.Close()
return false
}
return true
})

defer resp.Body.Close()
re.Equal(statusCode, resp.StatusCode)
output, err := io.ReadAll(resp.Body)
re.NoError(err)
resp.Body.Close()
return output
}
Loading