From abd44cbe615ecea5e4bd8e6d1bb7be63d1f4b2d6 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 24 Mar 2026 08:18:27 -0700 Subject: net/http: add a test for starting a server with no HTTP/2 and no TLS config Test for the fix in CL 758560. Change-Id: I34edf9f14dc5d6a569f20aa3d55d9d136a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/758661 Auto-Submit: Damien Neil Reviewed-by: Nicholas Husin LUCI-TryBot-Result: Go LUCI Reviewed-by: Nicholas Husin --- src/net/http/serve_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/net') diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index b2cf43cd3f..f2ba8705d1 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -18,7 +18,6 @@ import ( "encoding/json" "errors" "fmt" - "internal/synctest" "internal/testenv" "io" "log" @@ -44,6 +43,7 @@ import ( "sync/atomic" "syscall" "testing" + "testing/synctest" "time" ) @@ -7648,3 +7648,17 @@ func testServerTLSNextProtos(t *testing.T, mode testMode) { t.Fatalf("after running test: original NextProtos slice = %v, want %v", nextProtos, wantNextProtos) } } + +// Verifies that starting a server with HTTP/2 disabled and an empty TLSConfig does not panic. +// (Tests fix in CL 758560.) +func TestServerHTTP2Disabled(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + li := fakeNetListen() + srv := &Server{} + srv.Protocols = new(Protocols) + srv.Protocols.SetHTTP1(true) + go srv.ServeTLS(li, "", "") + synctest.Wait() + srv.Shutdown(t.Context()) + }) +} -- cgit v1.3-5-g9baa