1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:54:50 -07:00

net/http: wrap client errors (resolve comment 2151)

This commit is contained in:
kayos@tcp.direct 2023-12-30 14:12:17 -08:00
parent 208816a9de
commit be570e7883
No known key found for this signature in database
GPG Key ID: 2589E13D13502158

View File

@ -2128,15 +2128,17 @@ func testProbeZeroLengthBody(t *testing.T, mode testMode) {
}
}
func TestClientTimeoutErrorWrapping(t *testing.T) { run(t, testClientTimeoutErrorWrapping) }
func testClientTimeoutErrorWrapping(t *testing.T, mode testMode) {
func TestClientTimeoutReturnsContextDeadlineExceeded(t *testing.T) {
run(t, testClientTimeoutReturnsContextDeadlineExceeded)
}
func testClientTimeoutReturnsContextDeadlineExceeded(t *testing.T, mode testMode) {
doneCh := make(chan struct{})
defer close(doneCh)
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
<-doneCh
w.WriteHeader(200)
}))
// simulate a timeout and check that the error is wrapped by using errors.Is(err, context.DeadlineExceeded)
// check that, upon exceeding Client.Timeout, the returned error is context.DeadlineExceeded.
cst.c.Timeout = 1 * time.Millisecond
req, _ := NewRequest("GET", cst.ts.URL, nil)
_, err := cst.c.Do(req)