nettest, *: add option to run HTTP tests with in-memory network

To avoid ephemeral port / TIME_WAIT exhaustion with high --count
values, and to eventually detect leaked connections in tests. (Later
the memory network will register a Cleanup on the TB to verify that
everything's been shut down)

Updates tailscale/corp#27636

Change-Id: Id06f1ae750d8719c5a75d871654574a8226d2733
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2025-04-06 08:10:55 -07:00
committed by Brad Fitzpatrick
parent 6d117d64a2
commit c76d075472
6 changed files with 237 additions and 11 deletions

View File

@@ -28,6 +28,7 @@ import (
"tailscale.com/ipn/ipnstate"
"tailscale.com/net/memnet"
"tailscale.com/tailcfg"
"tailscale.com/tstest/nettest"
"tailscale.com/types/views"
"tailscale.com/util/httpm"
)
@@ -1508,7 +1509,7 @@ func TestCSRFProtect(t *testing.T) {
}
})
h := s.withCSRF(mux)
ser := httptest.NewServer(h)
ser := nettest.NewHTTPServer(nettest.GetNetwork(t), h)
defer ser.Close()
jar, err := cookiejar.New(nil)