File size: 1,415 Bytes
ea775bd | 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 | 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")
}
}
|