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:
Zach
2025-10-02 11:43:13 -06:00
committed by GitHub
parent 0d2ccacacd
commit 4d1003eace
18 changed files with 59 additions and 33 deletions
+4 -2
View File
@@ -1254,8 +1254,9 @@ func TestServer(t *testing.T) {
t.Logf("error creating request: %s", err.Error())
return false
}
client := &http.Client{}
// nolint:bodyclose
res, err := http.DefaultClient.Do(req)
res, err := client.Do(req)
if err != nil {
t.Logf("error hitting prometheus endpoint: %s", err.Error())
return false
@@ -1316,8 +1317,9 @@ func TestServer(t *testing.T) {
t.Logf("error creating request: %s", err.Error())
return false
}
client := &http.Client{}
// nolint:bodyclose
res, err := http.DefaultClient.Do(req)
res, err := client.Do(req)
if err != nil {
t.Logf("error hitting prometheus endpoint: %s", err.Error())
return false
+2 -1
View File
@@ -1242,7 +1242,8 @@ func TestSSH(t *testing.T) {
// true exits the loop.
return true
}
resp, err := http.DefaultClient.Do(req)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
t.Logf("HTTP GET http://localhost:8222/ %s", err)
return false