diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2019-05-07 16:25:05 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-09-25 04:18:18 +0000 |
| commit | 7fc2625ef16c9e271ca3016f761157ec082cc45a (patch) | |
| tree | 5df4a669824c976eaab8a0521017d23a5b281fc7 /src/net/http/client_test.go | |
| parent | caf45cde1873360d326af974575bd254b8011901 (diff) | |
| download | go-7fc2625ef16c9e271ca3016f761157ec082cc45a.tar.xz | |
net/http: propagate Client.Timeout down into Request's context deadline
Fixes #31657
Change-Id: I85e9595d3ea30d410f1f4b787925a6879a72bdf2
Reviewed-on: https://go-review.googlesource.com/c/go/+/175857
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/client_test.go')
| -rw-r--r-- | src/net/http/client_test.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/net/http/client_test.go b/src/net/http/client_test.go index ebcd6c9147..37c0390a73 100644 --- a/src/net/http/client_test.go +++ b/src/net/http/client_test.go @@ -1274,7 +1274,7 @@ func testClientTimeout(t *testing.T, h2 bool) { } else if !ne.Timeout() { t.Errorf("net.Error.Timeout = false; want true") } - if got := ne.Error(); !strings.Contains(got, "Client.Timeout exceeded") { + if got := ne.Error(); !strings.Contains(got, "(Client.Timeout") { t.Errorf("error string = %q; missing timeout substring", got) } case <-time.After(failTime): @@ -1917,3 +1917,22 @@ func TestClientCloseIdleConnections(t *testing.T) { t.Error("not closed") } } + +func TestClientPropagatesTimeoutToContext(t *testing.T) { + errDial := errors.New("not actually dialing") + c := &Client{ + Timeout: 5 * time.Second, + Transport: &Transport{ + DialContext: func(ctx context.Context, netw, addr string) (net.Conn, error) { + deadline, ok := ctx.Deadline() + if !ok { + t.Error("no deadline") + } else { + t.Logf("deadline in %v", deadline.Sub(time.Now()).Round(time.Second/10)) + } + return nil, errDial + }, + }, + } + c.Get("https://example.tld/") +} |
