Download internal/proxy/upstream_request_trace_test.go from xjackkx/rg: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/xjackkx/rg/resolve/main/internal/proxy/upstream_request_trace_test.go
- Command line
-
hf download hf://spaces/xjackkx/rg/internal/proxy/upstream_request_trace_test.go
-
curl -L -o upstream_request_trace_test.go https://huggingface.co/spaces/xjackkx/rg/resolve/main/internal/proxy/upstream_request_trace_test.go
1.42 kB
| package proxy | |
| import ( | |
| "errors" | |
| "net/http/httptrace" | |
| "testing" | |
| ) | |
| func TestUpstreamRequestTrace_NoConnNoWrite(t *testing.T) { | |
| trace := newUpstreamRequestTrace() | |
| if trace.shouldCommitEgress() { | |
| t.Fatal("shouldCommitEgress: got true, want false") | |
| } | |
| } | |
| func TestUpstreamRequestTrace_GotConnAndSuccessfulWrite(t *testing.T) { | |
| trace := newUpstreamRequestTrace() | |
| clientTrace := trace.clientTrace() | |
| clientTrace.GotConn(httptrace.GotConnInfo{}) | |
| clientTrace.WroteRequest(httptrace.WroteRequestInfo{Err: nil}) | |
| if !trace.shouldCommitEgress() { | |
| t.Fatal("shouldCommitEgress: got false, want true") | |
| } | |
| } | |
| func TestUpstreamRequestTrace_GotConnButWriteFailed(t *testing.T) { | |
| trace := newUpstreamRequestTrace() | |
| clientTrace := trace.clientTrace() | |
| clientTrace.GotConn(httptrace.GotConnInfo{}) | |
| clientTrace.WroteRequest(httptrace.WroteRequestInfo{Err: errors.New("write failed")}) | |
| if trace.shouldCommitEgress() { | |
| t.Fatal("shouldCommitEgress: got true, want false") | |
| } | |
| } | |
| func TestUpstreamRequestTrace_RetryAfterWriteFailure(t *testing.T) { | |
| trace := newUpstreamRequestTrace() | |
| clientTrace := trace.clientTrace() | |
| clientTrace.GotConn(httptrace.GotConnInfo{}) | |
| clientTrace.WroteRequest(httptrace.WroteRequestInfo{Err: errors.New("first attempt failed")}) | |
| clientTrace.WroteRequest(httptrace.WroteRequestInfo{Err: nil}) | |
| if !trace.shouldCommitEgress() { | |
| t.Fatal("shouldCommitEgress: got false, want true") | |
| } | |
| } | |