Skip to content

Commit 6f329be

Browse files
fix: Isolate HTTP transports in parallel tests to prevent connection issues (#3529)
1 parent 0710d0b commit 6f329be

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

github/github_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,29 @@ func setup(t *testing.T) (client *Client, mux *http.ServeMux, serverURL string)
5757
// server is a test HTTP server used to provide mock API responses.
5858
server := httptest.NewServer(apiHandler)
5959

60+
// Create a custom transport with isolated connection pool
61+
transport := &http.Transport{
62+
// Controls connection reuse - false allows reuse, true forces new connections for each request
63+
DisableKeepAlives: false,
64+
// Maximum concurrent connections per host (active + idle)
65+
MaxConnsPerHost: 10,
66+
// Maximum idle connections maintained per host for reuse
67+
MaxIdleConnsPerHost: 5,
68+
// Maximum total idle connections across all hosts
69+
MaxIdleConns: 20,
70+
// How long an idle connection remains in the pool before being closed
71+
IdleConnTimeout: 20 * time.Second,
72+
}
73+
74+
// Create HTTP client with the isolated transport
75+
httpClient := &http.Client{
76+
Transport: transport,
77+
Timeout: 30 * time.Second,
78+
}
6079
// client is the GitHub client being tested and is
6180
// configured to use test server.
62-
client = NewClient(nil)
81+
client = NewClient(httpClient)
82+
6383
url, _ := url.Parse(server.URL + baseURLPath + "/")
6484
client.BaseURL = url
6585
client.UploadURL = url

0 commit comments

Comments
 (0)