The DHCP test projects bind every server and fake peer on port 0 and read the port they got #411

Merged
claude merged 3 commits from feature/362-port-zero-dhcp-tests into develop 2026-11-13 03:19:23 -05:00
Owner

The DHCP test projects bind every server and fake peer on port 0 and read the port they got. Test code only; this is the DHCP half of #362 (the DNS and Web test projects follow in a second pull request, which closes #362 and #233).

  • Projects: Ninlil.Dhcp.Protocol.Dhcpv4.Tests, Ninlil.Dhcp.Protocol.Dhcpv6.Tests, Ninlil.Dhcp.Server.Relay.Tests.
  • Before: each test reserved a free port, released it and bound it again later, so another process could take it in between.
  • Now: the server starts on port 0 and the test reads Dhcpv4UdpListener.BoundPort or Dhcpv6UdpListener.BoundPort. Fake clients, fake upstream servers and relay targets are test-owned sockets on port 0. No product change was needed.
  • Helpers: every reserve-and-release helper in the three projects is deleted; the grep for GetFree(Udp|Tcp)?Port there returns nothing.
  • One bounded retry remains, by design: the two "restart on the same port" tests must bind the same number a second time. They retry that second start at most three times on AddressAlreadyInUse, with a comment.

Verified

  • With the reserved port stolen between reserve and bind, the old form of one test per project fails with "Address already in use"; the new form has no reserved port to steal.
  • Each project passes 10 runs in a row (18, 7 and 36 tests); build 0 warnings, 0 errors; csharpier clean.
  • Verifier: accepted. It confirmed by reading that no test can send to port 67, 68, 546 or 547, and that every test-owned socket is disposed.
  • Two notes, not fixed here: two rewritten summaries have an over-long line; and the restart tests cannot detect a leaked socket on Linux, because the listeners set SO_REUSEADDR. That was so before this change, which does not weaken them.

Refs #362

🤖 Generated with Claude Code

https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK

The DHCP test projects bind every server and fake peer on port 0 and read the port they got. Test code only; this is the DHCP half of #362 (the DNS and Web test projects follow in a second pull request, which closes #362 and #233). - **Projects:** `Ninlil.Dhcp.Protocol.Dhcpv4.Tests`, `Ninlil.Dhcp.Protocol.Dhcpv6.Tests`, `Ninlil.Dhcp.Server.Relay.Tests`. - **Before:** each test reserved a free port, released it and bound it again later, so another process could take it in between. - **Now:** the server starts on port 0 and the test reads `Dhcpv4UdpListener.BoundPort` or `Dhcpv6UdpListener.BoundPort`. Fake clients, fake upstream servers and relay targets are test-owned sockets on port 0. No product change was needed. - **Helpers:** every reserve-and-release helper in the three projects is deleted; the grep for `GetFree(Udp|Tcp)?Port` there returns nothing. - **One bounded retry remains, by design:** the two "restart on the same port" tests must bind the same number a second time. They retry that second start at most three times on `AddressAlreadyInUse`, with a comment. **Verified** - With the reserved port stolen between reserve and bind, the old form of one test per project fails with "Address already in use"; the new form has no reserved port to steal. - Each project passes 10 runs in a row (18, 7 and 36 tests); build 0 warnings, 0 errors; csharpier clean. - Verifier: accepted. It confirmed by reading that no test can send to port 67, 68, 546 or 547, and that every test-owned socket is disposed. - Two notes, not fixed here: two rewritten summaries have an over-long line; and the restart tests cannot detect a leaked socket on Linux, because the listeners set `SO_REUSEADDR`. That was so before this change, which does not weaken them. Refs #362 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The client socket is test-owned and binds port 0 too, so no test reserves a port and releases it before use. The restart test keeps the first port for its second start with a bounded retry.

Refs #362

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The client socket is test-owned and binds port 0 too, so no test reserves a port and releases it before use. The restart test keeps the first port for its second start with a bounded retry.

Refs #362

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
The DHCP relay tests bind every listener and fake peer on port 0 and read the port they got
All checks were successful
Build / Pack and Push NuGet Packages (dhcp) (pull_request) Successful in -2m13s
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Successful in -2m7s
Build / Pack and Push NuGet Packages (dns-server) (pull_request) Successful in -2m2s
Build / Stage Draft Release (push) Successful in -2m36s
Build / Pack and Push NuGet Packages (common) (push) Successful in -2m26s
Build / Pack and Push NuGet Packages (dhcp) (push) Successful in -2m7s
Build / Pack and Push NuGet Packages (dns-core) (push) Successful in -2m5s
Build / Pack and Push NuGet Packages (dns-server) (push) Successful in -2m5s
Build / Build Binary (linux-amd64) (pull_request) Successful in -54s
Build / Build Binary (linux-arm64) (pull_request) Successful in -1m5s
Build / Build Binary (macos-amd64) (pull_request) Successful in -1m12s
Build / Build Binary (macos-arm64) (pull_request) Successful in -1m10s
Build / Build Binary (windows-amd64) (pull_request) Successful in -1m3s
Build / Smoke Test the Windows Binary (pull_request) Successful in 16s
Build / Build Binary (linux-amd64) (push) Successful in -50s
Build / Build Binary (linux-arm64) (push) Successful in -46s
Build / Build Binary (macos-amd64) (push) Successful in -53s
Build / Build Binary (macos-arm64) (push) Successful in -1m14s
Build / Build Binary (windows-amd64) (push) Successful in -56s
Build / Smoke Test the Windows Binary (push) Successful in 15s
Build / Build Arch Linux Packages (pull_request) Successful in -2m24s
Build / Build and Push Image (pull_request) Successful in -2m19s
Build / Build Arch Linux Packages (push) Successful in -2m22s
Build / Build and Test Deb and RPM Packages (pull_request) Successful in -13s
Build / Build and Push Image (push) Successful in -2m32s
Build / Build and Test Deb and RPM Packages (push) Successful in -5s
Build / Publish Release (pull_request) Successful in -2m35s
Build / Pipeline (pull_request) Successful in 0s
Build / Publish Release (push) Successful in -2m35s
Build / Pipeline (push) Successful in 0s
596c5a8789
The relay listener binds port 0 and reports its port, and the fake upstream servers, clients and the unused upstream of the DHCPv6 agent tests are test-owned sockets, so no test reserves a port and releases it before use.

Refs #362

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
claude merged commit 98993573fc into develop 2026-11-13 03:19:23 -05:00
claude deleted branch feature/362-port-zero-dhcp-tests 2026-11-13 03:19:23 -05:00
Sign in to join this conversation.
No reviewers
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil!411
No description provided.