Skip to content

fix: Isolate HTTP transports in parallel tests to prevent connection issues #3529

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
Changes from all 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
22 changes: 21 additions & 1 deletion github/github_test.go
Original file line number Diff line number Diff line change
@@ -57,9 +57,29 @@ func setup(t *testing.T) (client *Client, mux *http.ServeMux, serverURL string)
// server is a test HTTP server used to provide mock API responses.
server := httptest.NewServer(apiHandler)

// Create a custom transport with isolated connection pool
transport := &http.Transport{
// Controls connection reuse - false allows reuse, true forces new connections for each request
DisableKeepAlives: false,
// Maximum concurrent connections per host (active + idle)
MaxConnsPerHost: 10,
// Maximum idle connections maintained per host for reuse
MaxIdleConnsPerHost: 5,
// Maximum total idle connections across all hosts
MaxIdleConns: 20,
// How long an idle connection remains in the pool before being closed
IdleConnTimeout: 20 * time.Second,
}

// Create HTTP client with the isolated transport
httpClient := &http.Client{
Transport: transport,
Timeout: 30 * time.Second,
}
// client is the GitHub client being tested and is
// configured to use test server.
client = NewClient(nil)
client = NewClient(httpClient)

url, _ := url.Parse(server.URL + baseURLPath + "/")
client.BaseURL = url
client.UploadURL = url