Skip to content

fix: workspaceapps: overloaded test server responds with 502s #5255

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

Merged
merged 6 commits into from
Dec 2, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
gosec
  • Loading branch information
mtojek committed Dec 2, 2022
commit 3aceb47b855500fb6f228bfd9b172949697d2d3e
15 changes: 13 additions & 2 deletions coderd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,33 @@ import (
// Issue: https://github.com/coder/coder/issues/5249
// While running tests in parallel, the web server seems to be overloaded and responds with HTTP 502.
// require.Eventually expects correct HTTP responses.

func doWithRetries(t require.TestingT, client *codersdk.Client, req *http.Request) (*http.Response, error) {
var resp *http.Response
var err error
require.Eventually(t, func() bool {
resp, err = client.HTTPClient.Do(req)
return resp.StatusCode != http.StatusBadGateway
if resp != nil && resp.StatusCode == http.StatusBadGateway {
resp.Body.Close()
return false
}
return true
}, testutil.WaitLong, testutil.IntervalFast)
return resp, err
}

// context-as-argument: context.Context should be the first parameter of a function (revive)
// #nosec
func requestWithRetries(t require.TestingT, client *codersdk.Client, ctx context.Context, method, path string, body interface{}, opts ...codersdk.RequestOption) (*http.Response, error) {
var resp *http.Response
var err error
require.Eventually(t, func() bool {
resp, err = client.Request(ctx, method, path, body, opts...)
return resp == nil || resp.StatusCode != http.StatusBadGateway
if resp != nil && resp.StatusCode == http.StatusBadGateway {
resp.Body.Close()
return false
}
return true
}, testutil.WaitLong, testutil.IntervalFast)
return resp, err
}