MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestIdleTimeoutFromEnv

Function TestIdleTimeoutFromEnv

internal/llm/llm_test.go:830–860  ·  view source on GitHub ↗

TestIdleTimeoutFromEnv pins the CODEHAMR_IDLE_TIMEOUT contract: a Go duration or bare-seconds string wins, anything else (unset, garbage, non-positive) falls back to the default. The default is deliberately generous because this is a dead-connection detector, not a loop guard.

(t *testing.T)

Source from the content-addressed store, hash-verified

828func TestNewHasNoHTTPTimeout(t *testing.T) {
829 c := New("http://example.test", "model", "token")
830 if c.HTTP.Timeout != 0 {
831 t.Fatalf("http.Client.Timeout must be 0 so per-turn context governs SSE lifetime; got %v", c.HTTP.Timeout)
832 }
833}
834
835// TestIdleTimeoutFromEnv pins the CODEHAMR_IDLE_TIMEOUT contract: a Go duration
836// or bare-seconds string wins, anything else (unset, garbage, non-positive)
837// falls back to the default. The default is deliberately generous because this
838// is a dead-connection detector, not a loop guard.
839func TestIdleTimeoutFromEnv(t *testing.T) {
840 cases := []struct {
841 val string
842 set bool
843 want time.Duration
844 }{
845 {set: false, want: streamIdleTimeout},
846 {val: "", set: true, want: streamIdleTimeout},
847 {val: "90m", set: true, want: 90 * time.Minute},
848 {val: "1h30m", set: true, want: 90 * time.Minute},
849 {val: "300", set: true, want: 300 * time.Second},
850 {val: "garbage", set: true, want: streamIdleTimeout},
851 {val: "0", set: true, want: streamIdleTimeout},
852 {val: "-5m", set: true, want: streamIdleTimeout},
853 // Bare seconds large enough to wrap the ×time.Second multiply to a
854 // small POSITIVE duration must fall back, not silently kill every
855 // live-but-slow stream mid-prefill.
856 {val: "18446744074", set: true, want: streamIdleTimeout},
857 {val: "9000000000", set: true, want: 9_000_000_000 * time.Second},
858 }
859 for _, tc := range cases {
860 if tc.set {
861 t.Setenv("CODEHAMR_IDLE_TIMEOUT", tc.val)
862 } else {
863 os.Unsetenv("CODEHAMR_IDLE_TIMEOUT")

Callers

nothing calls this directly

Calls 1

idleTimeoutFromEnvFunction · 0.85

Tested by

no test coverage detected