Start test servers on a port the system picks (closes #211)
check / check (push) Waiting to run

The internal/server and internal/ircserver tests picked a port by
opening a listener, reading its port and closing it. They then started
a server on that number. Another process could take the port in
between, and a test failed with "address already in use".

The IRC server tests now start the server on 127.0.0.1:0 and read the
port back from its listener. The HTTP server tests start the app with
port 0. The HTTP server now keeps the listener it binds, so the stop
test sends its long poll to the port the app was given.

Model: opus-5-5
This commit was merged in pull request #212.
This commit is contained in:
2026-10-27 13:34:45 +01:00
parent d444831f41
commit ecf47c37f5
4 changed files with 25 additions and 58 deletions
+3 -15
View File
@@ -137,20 +137,6 @@ func newTestEnvWithResolver(
brk := broker.New()
var listenConfig net.ListenConfig
listener, err := listenConfig.Listen(t.Context(), "tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen: %v", err)
}
addr := listener.Addr().String()
err = listener.Close()
if err != nil {
t.Fatalf("close listener: %v", err)
}
log := slog.New(slog.NewTextHandler(
os.Stderr,
&slog.HandlerOptions{Level: slog.LevelError}, //nolint:exhaustruct
@@ -160,7 +146,9 @@ func newTestEnvWithResolver(
log, cfg, database, brk, interval, deadline, resolve,
)
err = srv.Start(addr)
// Port 0 makes the system pick a free port. dial reads it
// back from the server's listener.
err = srv.Start("127.0.0.1:0")
if err != nil {
t.Fatalf("start irc server: %v", err)
}