Expand description
Test utilities for allocating unique network addresses.
This module provides thread-safe port allocation for tests using a guard pattern to prevent port reuse race conditions. The design eliminates intra-process races by:
- Binding to get a port while holding a TCP listener
- Registering the port atomically (while still holding the listener and registry lock)
- Only then releasing the listener (port now protected by registry entry)
This ensures no race window between port allocation and registration.
Structs§
- Port
Guard - A guard that reserves a port in the registry, preventing port reuse until dropped. The guard does NOT hold the actual listener - it just marks the port as reserved so that concurrent calls to next_addr() won’t return the same port.
Functions§
- next_
addr - next_
addr_ any - next_
addr_ for_ ip - Allocates a unique port and returns a guard that keeps it reserved.
- next_
addr_ v6