Skip to content

fix(tracker): replace address-keyed bootstrap containers with ordered vec - #2044

Open
josecelano wants to merge 2 commits into
torrust:developfrom
josecelano:2035-fix-duplicate-port-zero-tracker-instance-bootstrap
Open

fix(tracker): replace address-keyed bootstrap containers with ordered vec#2044
josecelano wants to merge 2 commits into
torrust:developfrom
josecelano:2035-fix-duplicate-port-zero-tracker-instance-bootstrap

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Replaces HashMap<SocketAddr, Container> with Vec<(ConfigurationInstanceId, Container)> so that duplicate port-zero configuration entries each receive their own container.

Bootstrap fix

  • AppContainer now stores HTTP and UDP instance containers in order-preserving Vecs keyed by (ConfigurationInstanceId, Container).
  • Lookup methods take a configuration index instead of SocketAddr.
  • Duplicate 0.0.0.0:0 entries no longer overwrite each other.

Test restructuring

  • Replaces the old tests/stats.rs + tests/servers/ tree with tests/aggregate_stats_port_zero.rs and tests/aggregate_stats_fixed_ports.rs, following the binary-per-configuration convention.
  • Each binary starts one tracker instance and runs scenario functions sequentially.
  • Both binaries include HTTP and UDP aggregate-statistics scenarios using the tracker-client library.
  • Splits tests/common/ into focused submodules: workspace.rs, announce.rs, statistics.rs.

Supporting changes

  • Adds http_announce and udp_announce helpers to packages/test-helpers.
  • Adds UDP dev-dependencies (torrust-tracker-client-lib, torrust-tracker-udp-protocol) to test-helpers.
  • Updates deny.toml to allow test-helpers as a wrapper for protocol crates.
  • Updates tests/AGENTS.md to reflect the new structure.

Validation

  • Focused tests for primitives, HTTP server, REST API server, UDP server, and integration binaries.
  • Full pre-commit checks: cargo machete, cargo deny check bans, linter all, documentation tests.
  • Full pre-push checks: nightly format, check, doc, and stable test suite.

Scope

This PR deliberately does not implement duplicate-port-zero aggregate-statistics filtering (#2039) or registry metadata migration (#2041).

Closes #2035

… vec

Replaces HashMap<SocketAddr, Container> with Vec<(ConfigurationInstanceId, Container)>
so that duplicate port-zero configuration entries each receive their own container.
Lookup methods now take an index instead of a SocketAddr.

Restructures integration tests to follow the binary-per-configuration convention:
one runner test per binary that starts the tracker once, then calls scenario
functions sequentially. Adds aggregate_stats_fixed_ports.rs and
aggregate_stats_port_zero.rs with both HTTP and UDP scenarios using the
tracker-client library. Splits tests/common/ into focused submodules.

Closes torrust#2035
Copilot AI review requested due to automatic review settings July 29, 2026 20:22
@josecelano josecelano self-assigned this Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #2035 by changing bootstrap container storage from an address-keyed map to an order-preserving list keyed by configuration instance identity, ensuring repeated 0.0.0.0:0 blocks do not overwrite each other. It also restructures integration tests into per-configuration binaries and introduces shared HTTP/UDP announce helpers in test-helpers.

Changes:

  • Replace HashMap<SocketAddr, Container> with Vec<(ConfigurationInstanceId, Container)> for HTTP/UDP instance containers and switch lookups to configuration indices.
  • Restructure integration tests into aggregate_stats_port_zero.rs and aggregate_stats_fixed_ports.rs, with shared helpers under tests/common/.
  • Add HTTP/UDP announce helpers to packages/test-helpers and adjust dependency policy (deny.toml).

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/stats.rs Removes legacy stats integration-test scaffold.
tests/servers/mod.rs Removes legacy servers test module root.
tests/servers/api/mod.rs Removes legacy API test module root.
tests/servers/api/contract/mod.rs Removes legacy contract test module root.
tests/servers/api/contract/stats/mod.rs Removes legacy stats contract scenarios (superseded by new binaries).
tests/common/workspace.rs New workspace/startup + registar-based endpoint discovery helpers.
tests/common/statistics.rs New REST API aggregate-statistics query helper.
tests/common/mod.rs Splits common helpers into submodules and re-exports them.
tests/common/announce.rs New wrappers delegating announces to test-helpers.
tests/aggregate_stats_port_zero.rs New port-zero multi-instance aggregate-statistics integration test binary.
tests/aggregate_stats_fixed_ports.rs New fixed-port multi-instance aggregate-statistics integration test binary.
tests/AGENTS.md Updates documentation to match the new integration-test structure.
src/container.rs Switches per-instance container storage to ordered vec keyed by configuration instance identity.
src/app.rs Updates instance startup to resolve containers by configuration index (not bind address).
packages/test-helpers/src/udp.rs Adds UDP announce helper performing connect→announce handshake.
packages/test-helpers/src/http.rs Adds HTTP announce helper using tracker-client + protocol types.
packages/test-helpers/src/lib.rs Exposes new http and udp helper modules.
packages/test-helpers/Cargo.toml Adds client/protocol deps required by new helpers.
docs/issues/open/2039-normalize-per-instance-event-metrics-policy/ISSUE.md Updates spec metadata/links (but currently includes a stale removed test path).
docs/issues/open/2039-normalize-per-instance-event-metrics-policy/evidence.md Restructures evidence doc (but currently contains a duplicated heading artifact).
docs/issues/open/2035-fix-duplicate-port-zero-tracker-instance-bootstrap/ISSUE.md Updates spec metadata/plan (but currently includes a stale removed test path).
deny.toml Allows torrust-tracker-test-helpers as an approved wrapper for protocol crates.
Cargo.lock Locks added dependencies for torrust-tracker-test-helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/common/workspace.rs
Comment on lines +122 to +124
map.keys()
.find(|b| b.protocol() == torrust_net_primitives::service_binding::Protocol::HTTP && b.bind_address().ip().is_loopback())
.map(|b| loopback_url(b.bind_address()))
Comment thread tests/common/workspace.rs
Comment on lines +68 to +73
let (container, jobs) = app::run().await;
// Allow spawned tasks (registar insertions, listener binds) to
// complete before we attempt to read the registar or make requests.
tokio::time::sleep(std::time::Duration::from_millis(500)).await;

(container, jobs)
Comment on lines +117 to +118
let addr: std::net::SocketAddr = url.as_str()[6..].parse().expect("UDP URL must parse to SocketAddr");
common::udp_announce(addr, &info_hash, &peer_id, 17548).await;
Comment on lines +119 to +120
let addr: std::net::SocketAddr = url.as_str()[6..].parse().expect("UDP URL must parse to SocketAddr");
common::udp_announce(addr, &info_hash, &peer_id, 17548).await;
- docs/issues/open/2035-fix-duplicate-port-zero-tracker-instance-bootstrap/ISSUE.md
- docs/issues/open/2036-add-runtime-service-registry-metadata/ISSUE.md
- evidence.md
- tests/servers/api/contract/stats/mod.rs
- docs/issues/open/2041-migrate-runtime-service-registry-metadata/ISSUE.md
- docs/events-architecture.md
- evidence.md
- tests/servers/api/contract/stats/mod.rs
Comment on lines +18 to 20
Add the exact tracker configuration, commands, observed REST statistics, and
post-change comparison for each probe here. Do not overwrite baseline evidence.# Event Metrics Normalization Evidence

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.02%. Comparing base (6af41e4) to head (75dc77a).

Files with missing lines Patch % Lines
src/container.rs 92.85% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2044      +/-   ##
===========================================
+ Coverage    81.63%   82.02%   +0.39%     
===========================================
  Files          346      346              
  Lines        24735    24733       -2     
  Branches     24735    24733       -2     
===========================================
+ Hits         20192    20288      +96     
+ Misses        4238     4135     -103     
- Partials       305      310       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix duplicate port-zero tracker instance bootstrap

2 participants