File size: 1,470 Bytes
5f82b66 845f74c 5f82b66 845f74c 5f82b66 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | package executor
import (
"net/http"
"testing"
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
)
func TestProxyAwareClient_KeepAlivePoolReuse(t *testing.T) {
cfg := &config.Config{}
cfg.HTTPKeepAlive.Enabled = true
cfg.HTTPKeepAlive.MaxIdleConns = 32
cfg.HTTPKeepAlive.MaxIdleConnsPerHost = 8
cfg.HTTPKeepAlive.IdleConnTimeoutSeconds = 30
auth := &cliproxyauth.Auth{}
c1 := newProxyAwareHTTPClient(t.Context(), cfg, auth, 0)
c2 := newProxyAwareHTTPClient(t.Context(), cfg, auth, 0)
if c1.Transport == nil || c2.Transport == nil {
t.Fatalf("expected non-nil transports")
}
if c1.Transport != c2.Transport {
t.Fatalf("expected pooled transport reuse")
}
}
func TestProxyAwareClient_KeepAliveDisabledNoPoolReuse(t *testing.T) {
cfg := &config.Config{}
cfg.HTTPKeepAlive.Enabled = false
auth := &cliproxyauth.Auth{ProxyURL: "http://127.0.0.1:8080"}
c1 := newProxyAwareHTTPClient(t.Context(), cfg, auth, 0)
c2 := newProxyAwareHTTPClient(t.Context(), cfg, auth, 0)
if c1.Transport == nil || c2.Transport == nil {
t.Fatalf("expected non-nil transports")
}
if c1.Transport == c2.Transport {
t.Fatalf("expected distinct transports when keepalive pool disabled")
}
tr, ok := c1.Transport.(*http.Transport)
if !ok {
t.Fatalf("expected *http.Transport")
}
if !tr.DisableKeepAlives {
t.Fatalf("expected keep-alives disabled when feature disabled")
}
}
|