myown / internal /runtime /executor /proxy_helpers_test.go
sshinmen's picture
fix: harden keep-alive fallback and tune default idle timeout
845f74c
Raw
History Blame Contribute Delete
1.47 kB
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")
}
}