Make discovery server optional via Option<u16> port#17
Conversation
|
@ivonnyssen Can you please mark PRs that are ready for review as such? Looks like there's a bunch now in draft mode, and Github requires them to be merged "ready for review" before I can approve :) |
Hm I thought I ran tests in parallel with no issues so far... What error are you getting? Would |
The issues are on MacOS. There the set_reuse_port does not help, as the os is holding on to the port for a bit, making tests either very slow - wait for port to be re-usable - or forcing them to be completely sequential. |
There was a problem hiding this comment.
Pull request overview
Updates the server configuration to allow disabling the UDP discovery responder by making the discovery port optional, primarily to avoid port-binding conflicts when running multiple servers (e.g., in integration tests).
Changes:
- Changed
Server::discovery_portfromu16toOption<u16>withNonedisabling discovery. - Updated
BoundServerto holdOption<BoundDiscoveryServer>and returnOption<SocketAddr>fromdiscovery_listen_addr(). - Made
DEFAULT_DISCOVERY_PORTpublic and documented it for downstream use.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/server/mod.rs |
Makes discovery binding optional and threads Option through the bound server APIs and startup logic. |
src/discovery.rs |
Exposes DEFAULT_DISCOVERY_PORT publicly with rustdoc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change Server.discovery_port from u16 to Option<u16>. When set to None, the discovery server is not started, which is useful for tests and environments where ASCOM discovery is not needed. This also fixes the dead field bug where Server.discovery_port was never actually used — Server::bind() always hardcoded DEFAULT_DISCOVERY_PORT (32227) via DiscoveryServer::for_alpaca_server_at(). Now the configured port is passed through to the discovery server. Breaking change: discovery_port is now Option<u16> (default Some(32227)). discovery_listen_addr() now returns Option<SocketAddr>. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Expose the ASCOM Alpaca default discovery port (32227) as a public constant so downstream crates can reference it instead of duplicating the magic number. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Replace redundant closure with method reference for discovery_listen_addr - Restructure if-let/else to match for start() to satisfy redundant_else lint
6219465 to
5e155bd
Compare
5e155bd to
300301f
Compare
Summary
Changes
Server's discovery port fromu16toOption<u16>, allowing the discovery server to be disabled entirely by passingNone. Also makesDEFAULT_DISCOVERY_PORTpublic so consumers can reference it.Motivation
When running multiple Alpaca servers in integration tests, each server tries to bind the discovery UDP socket, causing port conflicts. Making the discovery server optional allows test servers to skip discovery binding entirely, avoiding these conflicts.
Changes
src/server/mod.rs:Server::discovery_portchanged fromu16toOption<u16>BoundServer::discoverychanged fromBoundDiscoveryServertoOption<BoundDiscoveryServer>BoundServer::discovery_listen_addr()returnsOption<SocketAddr>BoundServer::start()restructured to handle both casessrc/discovery.rs:DEFAULT_DISCOVERY_PORTchanged frompub(crate)topubwith documentationTest plan
cargo clippypasses (full CI feature matrix verified)Server::new(...)withSome(port)behaves identically to beforeServer::new(...)withNoneskips discovery server entirelyDEFAULT_DISCOVERY_PORTaccessible from downstream crates