mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00: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:
@@ -87,6 +87,7 @@ func New(options Options) (Reporter, error) {
|
||||
deploymentURL: deploymentURL,
|
||||
snapshotURL: snapshotURL,
|
||||
startedAt: dbtime.Now(),
|
||||
client: &http.Client{},
|
||||
}
|
||||
go reporter.runSnapshotter()
|
||||
return reporter, nil
|
||||
@@ -119,6 +120,7 @@ type remoteReporter struct {
|
||||
snapshotURL *url.URL
|
||||
startedAt time.Time
|
||||
shutdownAt *time.Time
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func (r *remoteReporter) Enabled() bool {
|
||||
@@ -142,7 +144,7 @@ func (r *remoteReporter) reportSync(snapshot *Snapshot) {
|
||||
return
|
||||
}
|
||||
req.Header.Set(VersionHeader, buildinfo.Version())
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
// If the request fails it's not necessarily an error.
|
||||
// In an airgapped environment, it's fine if this fails!
|
||||
|
||||
Reference in New Issue
Block a user