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:
parent
208816a9de
commit
be570e7883
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user