test(https): give the TLS tests ports of their own

The new tests reused ports the existing suite already binds — 8095 with
ShouldSurviveAbuseHTTP1, and 8097/8098 with ShouldFallbackUnknownRoutes'
plaintext and HTTP/3 listeners. SO_REUSEADDR does not let two live
listeners share a port, so under the parallel runner whichever bound
second failed, and which test that was came down to scheduling. Move the
TLS tests to 8110-8114, which nothing else uses.

That collision also showed up as a SIGABRT rather than a reported error,
so harden the path it took: ~ListenerHTTP1 calls Stop(), which joins
threads and touches sockets and can therefore throw. A second listener
failing to bind unwinds past a live first one, and a throw out of its
destructor mid-unwind terminates the process — turning a diagnosable bind
failure into a crash. Swallow it there, where there is nothing left to
report it to.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
catbot 2026-07-28 20:34:23 +00:00
commit 14e0a6bab1
4 changed files with 34 additions and 23 deletions

View file

@ -132,13 +132,13 @@ namespace {
return CreateResponseHTTP("200", request.scheme);
};
ListenerAsyncHTTP1 listener(8097, std::move(routes),
ListenerAsyncHTTP1 listener(8111, std::move(routes),
TLSServerCredentials{ .selfSigned = true });
Check(WaitForPort(8097, std::chrono::seconds(2)), "the HTTPS listener came up");
Check(WaitForPort(8111, std::chrono::seconds(2)), "the HTTPS listener came up");
// --cacert, not --insecure: curl does the full chain and hostname
// check, so this is a real verification of what we present.
const std::string base = "https://localhost:8097";
const std::string base = "https://localhost:8111";
const std::string curl = "curl -sS --http1.1 --cacert '" + files.certificate.string() + "' ";
Check(Run(curl + base + "/hello") == "Hello curl!", "curl GET over TLS");
@ -203,13 +203,13 @@ namespace {
+ files.privateKey.string() + "')\n"
"handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory='"
+ root.string() + "')\n"
"server = http.server.HTTPServer(('127.0.0.1', 8098), handler)\n"
"server = http.server.HTTPServer(('127.0.0.1', 8112), handler)\n"
"server.socket = context.wrap_socket(server.socket, server_side=True)\n"
"server.serve_forever()\n";
Child server({"python3", "-c", script});
Check(server.Started(), "python3 TLS http.server was spawned");
if (!WaitForPort(8098, std::chrono::seconds(10))) {
if (!WaitForPort(8112, std::chrono::seconds(10))) {
std::println("skipping the python half: the TLS http.server never came up");
return;
}
@ -218,22 +218,22 @@ namespace {
// rather than the caPem blob the self-contained test uses.
TLSClientCredentials credentials;
credentials.caPath = files.certificate.string();
ClientHTTP1 client("localhost", 8098, credentials);
ClientHTTP1 client("localhost", 8112, credentials);
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/hello.txt", "localhost:8098"));
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/hello.txt", "localhost:8112"));
Check(response.status == "200", "python TLS GET status");
Check(response.body == content, "python TLS GET body");
Check(!client.Connected(), "an HTTP/1.0 response closes the TLS connection");
HTTPResponse listing = client.Send(CreateRequestHTTP("GET", "/", "localhost:8098"));
HTTPResponse listing = client.Send(CreateRequestHTTP("GET", "/", "localhost:8112"));
Check(listing.status == "200", "python TLS directory listing status");
Check(listing.body.find("hello.txt") != std::string::npos,
"python TLS directory listing body");
HTTPResponse missing = client.Send(CreateRequestHTTP("GET", "/nothing-here", "localhost:8098"));
HTTPResponse missing = client.Send(CreateRequestHTTP("GET", "/nothing-here", "localhost:8112"));
Check(missing.status == "404", "python TLS 404");
HTTPResponse head = client.Send(CreateRequestHTTP("HEAD", "/hello.txt", "localhost:8098"));
HTTPResponse head = client.Send(CreateRequestHTTP("HEAD", "/hello.txt", "localhost:8112"));
Check(head.status == "200", "python TLS HEAD status");
Check(head.body.empty(), "python TLS HEAD has no body");
}