Download internal/runtime/executor/proxy_helpers_test.go from shimen/myown: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/shimen/myown/resolve/main/internal/runtime/executor/proxy_helpers_test.go
- Command line
-
hf download hf://spaces/shimen/myown/internal/runtime/executor/proxy_helpers_test.go
-
curl -L -o proxy_helpers_test.go https://huggingface.co/spaces/shimen/myown/resolve/main/internal/runtime/executor/proxy_helpers_test.go
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") | |
| } | |
| } | |