diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-11-02 10:29:08 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-11-02 20:15:19 +0000 |
| commit | 547eb8d699a63512cf58c7eeae5517ead7debf50 (patch) | |
| tree | f6b4f8053b6b1f4a2a14d24eb1b3959c165fc106 /src/net/http/serve_test.go | |
| parent | 39d3c4ad35984b470b2928a37ea4a7e721b1225a (diff) | |
| download | go-547eb8d699a63512cf58c7eeae5517ead7debf50.tar.xz | |
net/http: remove arbitrary timeouts in tests of Server.ErrorLog
This also allows us to remove the chanWriter helper from the test,
using a simpler strings.Builder instead, relying on
clientServerTest.close for synchronization.
(I don't think this runs afoul of #38370, because the handler
functions themselves in these tests should never be executed,
let alone result in an asynchronous write to the error log.)
Fixes #57599.
Change-Id: I45c6cefca0bb218f6f9a9659de6bde454547f704
Reviewed-on: https://go-review.googlesource.com/c/go/+/539436
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/net/http/serve_test.go')
| -rw-r--r-- | src/net/http/serve_test.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index 00230020e7..0c76f1bcc4 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -1400,27 +1400,28 @@ func TestTLSHandshakeTimeout(t *testing.T) { run(t, testTLSHandshakeTimeout, []testMode{https1Mode, http2Mode}) } func testTLSHandshakeTimeout(t *testing.T, mode testMode) { - errc := make(chanWriter, 10) // but only expecting 1 - ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {}), + errLog := new(strings.Builder) + cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {}), func(ts *httptest.Server) { ts.Config.ReadTimeout = 250 * time.Millisecond - ts.Config.ErrorLog = log.New(errc, "", 0) + ts.Config.ErrorLog = log.New(errLog, "", 0) }, - ).ts + ) + ts := cst.ts + conn, err := net.Dial("tcp", ts.Listener.Addr().String()) if err != nil { t.Fatalf("Dial: %v", err) } - defer conn.Close() - var buf [1]byte n, err := conn.Read(buf[:]) if err == nil || n != 0 { t.Errorf("Read = %d, %v; want an error and no bytes", n, err) } + conn.Close() - v := <-errc - if !strings.Contains(v, "timeout") && !strings.Contains(v, "TLS handshake") { + cst.close() + if v := errLog.String(); !strings.Contains(v, "timeout") && !strings.Contains(v, "TLS handshake") { t.Errorf("expected a TLS handshake timeout error; got %q", v) } } |
