internal/server tests can fail at random when another process takes the port they picked #211

Closed
opened 2026-10-27 11:39:04 +01:00 by clawbot · 1 comment
Collaborator

freePort in internal/server/server_test.go finds a free TCP port by opening a listener, reading its port and closing it again. The test then starts the server on that port number. Between the close and the server's bind, any other process can take the port. On this host many test runs share the machine, and TestServeAfterStopDoesNotStopApp failed once with bind: address already in use during the work on #209. Three tests use freePort, so each can fail at random and turn next red. Read from the code on 53009cf.

Fix: a test server must get a port no other process can take first, for example by binding port 0 and reading back the port it was given, or by handing the test's open listener to the server. Use the plainest way the server's code already allows; change product code only if it cannot be done in the tests, and then only as much as needed.

Definition of done

  1. No test in the repo picks a port by opening and closing a listener and then binding the number again.
  2. internal/server passes repeated script/test runs on the busy host with no address already in use error.
  3. Every package stays under the 20-second test target.
  4. One reviewed PR against next.

Model: opus-5-5

`freePort` in `internal/server/server_test.go` finds a free TCP port by opening a listener, reading its port and closing it again. The test then starts the server on that port number. Between the close and the server's bind, any other process can take the port. On this host many test runs share the machine, and `TestServeAfterStopDoesNotStopApp` failed once with `bind: address already in use` during the work on https://git.eeqj.de/sneak/neoirc/issues/209. Three tests use `freePort`, so each can fail at random and turn `next` red. Read from the code on `53009cf`. Fix: a test server must get a port no other process can take first, for example by binding port 0 and reading back the port it was given, or by handing the test's open listener to the server. Use the plainest way the server's code already allows; change product code only if it cannot be done in the tests, and then only as much as needed. ## Definition of done 1. No test in the repo picks a port by opening and closing a listener and then binding the number again. 2. `internal/server` passes repeated `script/test` runs on the busy host with no `address already in use` error. 3. Every package stays under the 20-second test target. 4. One reviewed PR against `next`. Model: opus-5-5
Author
Collaborator

Fixed in #212. The internal/server and internal/ircserver tests now start their servers on port 0, so the system picks a free port. Only test files change.

Model: opus-5-5

Fixed in https://git.eeqj.de/sneak/neoirc/pulls/212. The `internal/server` and `internal/ircserver` tests now start their servers on port 0, so the system picks a free port. Only test files change. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/neoirc#211