mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: remove initial global HTTP client usage (#20128)
This PR makes the initial steps at removing usage of the global Go HTTP client, which was seen to have impacts on test flakiness in https://github.com/coder/internal/issues/1020. The first commit removes uses from tests, with the exception of one test that is tightly coupled to the default client. The second commit makes easy/low-risk removals from application code. This should have some impact to reduce test flakiness.
This commit is contained in:
@@ -495,6 +495,7 @@ func TestProvisionerDaemon_PrometheusEnabled(t *testing.T) {
|
||||
// Fetch metrics from Prometheus endpoint
|
||||
var req *http.Request
|
||||
var res *http.Response
|
||||
httpClient := &http.Client{}
|
||||
require.Eventually(t, func() bool {
|
||||
req, err = http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
|
||||
if err != nil {
|
||||
@@ -503,7 +504,7 @@ func TestProvisionerDaemon_PrometheusEnabled(t *testing.T) {
|
||||
}
|
||||
|
||||
// nolint:bodyclose
|
||||
res, err = http.DefaultClient.Do(req)
|
||||
res, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
t.Logf("unable to call Prometheus endpoint: %s", err.Error())
|
||||
return false
|
||||
|
||||
@@ -114,11 +114,12 @@ func TestWorkspaceProxy_Server_PrometheusEnabled(t *testing.T) {
|
||||
|
||||
// Fetch metrics from Prometheus endpoint
|
||||
var res *http.Response
|
||||
client := &http.Client{}
|
||||
require.Eventually(t, func() bool {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://127.0.0.1:%d", prometheusPort), nil)
|
||||
assert.NoError(t, err)
|
||||
// nolint:bodyclose
|
||||
res, err = http.DefaultClient.Do(req)
|
||||
res, err = client.Do(req)
|
||||
return err == nil
|
||||
}, testutil.WaitShort, testutil.IntervalFast)
|
||||
defer res.Body.Close()
|
||||
|
||||
@@ -43,13 +43,14 @@ func TestServer_Single(t *testing.T) {
|
||||
)
|
||||
clitest.Start(t, inv.WithContext(ctx))
|
||||
accessURL := waitAccessURL(t, cfg)
|
||||
client := &http.Client{}
|
||||
require.Eventually(t, func() bool {
|
||||
reqCtx := testutil.Context(t, testutil.IntervalMedium)
|
||||
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, accessURL.String()+"/healthz", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Log("/healthz not ready yet")
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user