Skip to content

Overhaul Packages Testing: Add tests for udp-tracker-core package #1348

Closed

Description

@josecelano

Add tests for udp-tracker-core package.

Initial Code Coverage

cargo llvm-cov --package bittorrent-udp-tracker-core

Filtered lines for the package:

Filename                                                           Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
udp-tracker-core/src/connection_cookie.rs                               19                 2    89.47%           8                 0   100.00%          81                 2    97.53%           0                 0         -
udp-tracker-core/src/container.rs                                        2                 2     0.00%           2                 2     0.00%          39                39     0.00%           0                 0         -
udp-tracker-core/src/crypto/keys.rs                                     19                 2    89.47%          12                 2    83.33%          43                 6    86.05%           0                 0         -
udp-tracker-core/src/services/announce.rs                               31                31     0.00%          11                11     0.00%          69                69     0.00%           0                 0         -
udp-tracker-core/src/services/banning.rs                                23                 3    86.96%          12                 1    91.67%          85                 4    95.29%           0                 0         -
udp-tracker-core/src/services/connect.rs                                33                 0   100.00%          15                 0   100.00%         164                 0   100.00%           0                 0         -
udp-tracker-core/src/services/mod.rs                                     9                 0   100.00%           9                 0   100.00%          28                 0   100.00%           0                 0         -
udp-tracker-core/src/services/scrape.rs                                 28                28     0.00%          11                11     0.00%          59                59     0.00%           0                 0         -
udp-tracker-core/src/statistics/event/handler.rs                        41                 1    97.56%          14                 0   100.00%         101                 0   100.00%           0                 0         -
udp-tracker-core/src/statistics/event/listener.rs                        6                 6     0.00%           2                 2     0.00%           5                 5     0.00%           0                 0         -
udp-tracker-core/src/statistics/event/sender.rs                          5                 1    80.00%           3                 1    66.67%           5                 1    80.00%           0                 0         -
udp-tracker-core/src/statistics/keeper.rs                               17                 4    76.47%           9                 3    66.67%          51                11    78.43%           0                 0         -
udp-tracker-core/src/statistics/repository.rs                           35                 1    97.14%          16                 1    93.75%          48                 3    93.75%           0                 0         -
udp-tracker-core/src/statistics/services.rs                             11                 0   100.00%           5                 0   100.00%          59                 0   100.00%           0                 0         -
udp-tracker-core/src/statistics/setup.rs                                 8                 0   100.00%           5                 0   100.00%          41                 0   100.00%           0                 0         -

Full report:

Filename                                                           Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clock/src/clock/mod.rs                                                   2                 2     0.00%           2                 2     0.00%           6                 6     0.00%           0                 0         -
clock/src/clock/stopped/mod.rs                                          31                31     0.00%          15                15     0.00%          59                59     0.00%           0                 0         -
clock/src/clock/working/mod.rs                                           2                 2     0.00%           2                 2     0.00%           6                 6     0.00%           0                 0         -
clock/src/conv/mod.rs                                                    3                 3     0.00%           3                 3     0.00%          13                13     0.00%           0                 0         -
configuration/src/lib.rs                                                30                18    40.00%          19                 7    63.16%          90                41    54.44%           0                 0         -
configuration/src/logging.rs                                            32                32     0.00%           5                 5     0.00%          45                45     0.00%           0                 0         -
configuration/src/v2_0_0/core.rs                                        20                 8    60.00%          13                 3    76.92%          57                16    71.93%           0                 0         -
configuration/src/v2_0_0/database.rs                                     7                 4    42.86%           4                 1    75.00%          23                11    52.17%           0                 0         -
configuration/src/v2_0_0/health_check_api.rs                             2                 0   100.00%           2                 0   100.00%           8                 0   100.00%           0                 0         -
configuration/src/v2_0_0/http_tracker.rs                                 3                 3     0.00%           3                 3     0.00%          12                12     0.00%           0                 0         -
configuration/src/v2_0_0/logging.rs                                      2                 0   100.00%           2                 0   100.00%           8                 0   100.00%           0                 0         -
configuration/src/v2_0_0/mod.rs                                         42                42     0.00%          11                11     0.00%          59                59     0.00%           0                 0         -
configuration/src/v2_0_0/network.rs                                      3                 0   100.00%           3                 0   100.00%          12                 0   100.00%           0                 0         -
configuration/src/v2_0_0/tracker_api.rs                                 10                 5    50.00%           6                 1    83.33%          24                 5    79.17%           0                 0         -
configuration/src/v2_0_0/udp_tracker.rs                                  3                 3     0.00%           3                 3     0.00%          12                12     0.00%           0                 0         -
located-error/src/lib.rs                                                 7                 7     0.00%           5                 5     0.00%          26                26     0.00%           0                 0         -
primitives/src/core.rs                                                   8                 8     0.00%           4                 4     0.00%          17                17     0.00%           0                 0         -
primitives/src/pagination.rs                                            13                13     0.00%           4                 4     0.00%          21                21     0.00%           0                 0         -
primitives/src/peer.rs                                                  72                72     0.00%          42                42     0.00%         211               211     0.00%           0                 0         -
primitives/src/swarm_metadata.rs                                         1                 1     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
primitives/src/torrent_metrics.rs                                        1                 1     0.00%           1                 1     0.00%           6                 6     0.00%           0                 0         -
test-helpers/src/configuration.rs                                       24                22     8.33%          11                 9    18.18%         124                74    40.32%           0                 0         -
test-helpers/src/logging.rs                                             52                52     0.00%          18                18     0.00%          82                82     0.00%           0                 0         -
test-helpers/src/random.rs                                               1                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
torrent-repository/src/entry/mutex_parking_lot.rs                        9                 9     0.00%           9                 9     0.00%          27                27     0.00%           0                 0         -
torrent-repository/src/entry/mutex_std.rs                                9                 9     0.00%           9                 9     0.00%          29                29     0.00%           0                 0         -
torrent-repository/src/entry/mutex_tokio.rs                             25                25     0.00%          17                17     0.00%          35                35     0.00%           0                 0         -
torrent-repository/src/entry/peer_list.rs                               23                23     0.00%          13                13     0.00%          53                53     0.00%           0                 0         -
torrent-repository/src/entry/rw_lock_parking_lot.rs                      9                 9     0.00%           9                 9     0.00%          27                27     0.00%           0                 0         -
torrent-repository/src/entry/single.rs                                  23                23     0.00%           9                 9     0.00%          54                54     0.00%           0                 0         -
torrent-repository/src/repository/dash_map_mutex_std.rs                 47                47     0.00%          15                15     0.00%          75                75     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_std.rs                        37                37     0.00%          16                16     0.00%          88                88     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_std_mutex_std.rs              40                40     0.00%          14                14     0.00%          89                89     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_std_mutex_tokio.rs            66                66     0.00%          25                25     0.00%         125               125     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_tokio.rs                      72                72     0.00%          27                27     0.00%         100               100     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_tokio_mutex_std.rs            79                79     0.00%          26                26     0.00%          99                99     0.00%           0                 0         -
torrent-repository/src/repository/rw_lock_tokio_mutex_tokio.rs          89                89     0.00%          24                24     0.00%         104               104     0.00%           0                 0         -
torrent-repository/src/repository/skip_map_mutex_std.rs                126               123     2.38%          42                41     2.38%         228               223     2.19%           0                 0         -
tracker-core/src/announce_handler.rs                                    39                39     0.00%          11                11     0.00%          94                94     0.00%           0                 0         -
tracker-core/src/authentication/handler.rs                              64                64     0.00%          17                17     0.00%          97                97     0.00%           0                 0         -
tracker-core/src/authentication/key/mod.rs                              17                17     0.00%           3                 3     0.00%          31                31     0.00%           0                 0         -
tracker-core/src/authentication/key/peer_key.rs                         28                28     0.00%          10                10     0.00%          51                51     0.00%           0                 0         -
tracker-core/src/authentication/key/repository/in_memory.rs             23                23     0.00%          10                10     0.00%          25                25     0.00%           0                 0         -
tracker-core/src/authentication/key/repository/persisted.rs             15                15     0.00%           4                 4     0.00%          17                17     0.00%           0                 0         -
tracker-core/src/authentication/service.rs                              16                16     0.00%           6                 6     0.00%          31                31     0.00%           0                 0         -
tracker-core/src/container.rs                                            1                 1     0.00%           1                 1     0.00%          45                45     0.00%           0                 0         -
tracker-core/src/databases/driver/mod.rs                                 9                 9     0.00%           1                 1     0.00%           8                 8     0.00%           0                 0         -
tracker-core/src/databases/driver/mysql.rs                             161               161     0.00%          31                31     0.00%         190               190     0.00%           0                 0         -
tracker-core/src/databases/driver/sqlite.rs                            217               217     0.00%          33                33     0.00%         208               208     0.00%           0                 0         -
tracker-core/src/databases/error.rs                                      7                 7     0.00%           4                 4     0.00%          31                31     0.00%           0                 0         -
tracker-core/src/databases/mod.rs                                        5                 5     0.00%           2                 2     0.00%           4                 4     0.00%           0                 0         -
tracker-core/src/databases/setup.rs                                      6                 6     0.00%           1                 1     0.00%           6                 6     0.00%           0                 0         -
tracker-core/src/error.rs                                                4                 4     0.00%           4                 4     0.00%          12                12     0.00%           0                 0         -
tracker-core/src/scrape_handler.rs                                      11                11     0.00%           3                 3     0.00%          19                19     0.00%           0                 0         -
tracker-core/src/torrent/manager.rs                                     11                11     0.00%           3                 3     0.00%          28                28     0.00%           0                 0         -
tracker-core/src/torrent/repository/in_memory.rs                        19                18     5.26%          10                 9    10.00%          36                33     8.33%           0                 0         -
tracker-core/src/torrent/repository/persisted.rs                         3                 3     0.00%           3                 3     0.00%          11                11     0.00%           0                 0         -
tracker-core/src/torrent/services.rs                                    23                23     0.00%           5                 5     0.00%          49                49     0.00%           0                 0         -
tracker-core/src/whitelist/authorization.rs                              5                 5     0.00%           4                 4     0.00%          13                13     0.00%           0                 0         -
tracker-core/src/whitelist/manager.rs                                   25                25     0.00%           7                 7     0.00%          26                26     0.00%           0                 0         -
tracker-core/src/whitelist/repository/in_memory.rs                      14                14     0.00%           8                 8     0.00%          17                17     0.00%           0                 0         -
tracker-core/src/whitelist/repository/persisted.rs                      22                22     0.00%           4                 4     0.00%          24                24     0.00%           0                 0         -
tracker-core/src/whitelist/setup.rs                                      1                 1     0.00%           1                 1     0.00%           7                 7     0.00%           0                 0         -
udp-protocol/src/peer_builder.rs                                         1                 1     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
udp-tracker-core/src/connection_cookie.rs                               19                 2    89.47%           8                 0   100.00%          81                 2    97.53%           0                 0         -
udp-tracker-core/src/container.rs                                        2                 2     0.00%           2                 2     0.00%          39                39     0.00%           0                 0         -
udp-tracker-core/src/crypto/keys.rs                                     19                 2    89.47%          12                 2    83.33%          43                 6    86.05%           0                 0         -
udp-tracker-core/src/services/announce.rs                               31                31     0.00%          11                11     0.00%          69                69     0.00%           0                 0         -
udp-tracker-core/src/services/banning.rs                                23                 3    86.96%          12                 1    91.67%          85                 4    95.29%           0                 0         -
udp-tracker-core/src/services/connect.rs                                33                 0   100.00%          15                 0   100.00%         164                 0   100.00%           0                 0         -
udp-tracker-core/src/services/mod.rs                                     9                 0   100.00%           9                 0   100.00%          28                 0   100.00%           0                 0         -
udp-tracker-core/src/services/scrape.rs                                 28                28     0.00%          11                11     0.00%          59                59     0.00%           0                 0         -
udp-tracker-core/src/statistics/event/handler.rs                        41                 1    97.56%          14                 0   100.00%         101                 0   100.00%           0                 0         -
udp-tracker-core/src/statistics/event/listener.rs                        6                 6     0.00%           2                 2     0.00%           5                 5     0.00%           0                 0         -
udp-tracker-core/src/statistics/event/sender.rs                          5                 1    80.00%           3                 1    66.67%           5                 1    80.00%           0                 0         -
udp-tracker-core/src/statistics/keeper.rs                               17                 4    76.47%           9                 3    66.67%          51                11    78.43%           0                 0         -
udp-tracker-core/src/statistics/repository.rs                           35                 1    97.14%          16                 1    93.75%          48                 3    93.75%           0                 0         -
udp-tracker-core/src/statistics/services.rs                             11                 0   100.00%           5                 0   100.00%          59                 0   100.00%           0                 0         -
udp-tracker-core/src/statistics/setup.rs                                 8                 0   100.00%           5                 0   100.00%          41                 0   100.00%           0                 0         -
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                 2059              1807    12.24%         756               614    18.78%        4029              3140    22.07%           0                 0         -

Activity

  1. added theissue type on Mar 3, 2025
  2. changed the title [-]Overhaul Packages Testing: add tests for `udp-tracker-core` package[/-] [+]Overhaul Packages Testing: Add tests for `udp-tracker-core` package[/+] on Mar 3, 2025
  3. josecelano commented on Mar 3, 2025

    @josecelano
    MemberAuthor

    I'm getting an error trying to generate the coverage report for this package:

    error[E0432]: unresolved import `tokio::time`
       --> packages/udp-tracker-core/src/services/banning.rs:22:12
        |
    22  | use tokio::time::Instant;
        |            ^^^^ could not find `time` in `tokio`
        |
    note: found an item that was configured out
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:556:13
        |
    556 |     pub mod time;
        |             ^^^^
    note: the item is gated behind the `time` feature
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:555:1
        |
    555 | / cfg_time! {
    556 | |     pub mod time;
    557 | | }
        | |_^
        = note: this error originates in the macro `cfg_time` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0433]: failed to resolve: could not find `time` in `tokio`
       --> packages/udp-tracker-core/src/services/banning.rs:40:53
        |
    40  |             last_connection_id_errors_reset: tokio::time::Instant::now(),
        |                                                     ^^^^ could not find `time` in `tokio`
        |
    note: found an item that was configured out
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:556:13
        |
    556 |     pub mod time;
        |             ^^^^
    note: the item is gated behind the `time` feature
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:555:1
        |
    555 | / cfg_time! {
    556 | |     pub mod time;
    557 | | }
        | |_^
        = note: this error originates in the macro `cfg_time` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider importing this struct
        |
    18  + use std::time::Instant;
        |
    help: if you import `Instant`, refer to it directly
        |
    40  -             last_connection_id_errors_reset: tokio::time::Instant::now(),
    40  +             last_connection_id_errors_reset: Instant::now(),
        |
    
    Some errors have detailed explanations: E0432, E0433.
    For more information about an error, try `rustc --explain E0432`.
    error: could not compile `bittorrent-udp-tracker-core` (lib test) due to 2 previous errors
    error: process didn't exit successfully: `/home/josecelano/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo test --tests --manifest-path /home/josecelano/Documents/git/committer/me/github/torrust/torrust-tracker/packages/udp-tracker-core/Cargo.toml --target-dir /home/josecelano/Documents/git/committer/me/github/torrust/torrust-tracker/target/llvm-cov-target` (exit status: 101)
    
  4. josecelano commented on Mar 4, 2025

    @josecelano
    MemberAuthor

    I'm getting an error trying to generate the coverage report for this package:

    error[E0432]: unresolved import `tokio::time`
       --> packages/udp-tracker-core/src/services/banning.rs:22:12
        |
    22  | use tokio::time::Instant;
        |            ^^^^ could not find `time` in `tokio`
        |
    note: found an item that was configured out
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:556:13
        |
    556 |     pub mod time;
        |             ^^^^
    note: the item is gated behind the `time` feature
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:555:1
        |
    555 | / cfg_time! {
    556 | |     pub mod time;
    557 | | }
        | |_^
        = note: this error originates in the macro `cfg_time` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0433]: failed to resolve: could not find `time` in `tokio`
       --> packages/udp-tracker-core/src/services/banning.rs:40:53
        |
    40  |             last_connection_id_errors_reset: tokio::time::Instant::now(),
        |                                                     ^^^^ could not find `time` in `tokio`
        |
    note: found an item that was configured out
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:556:13
        |
    556 |     pub mod time;
        |             ^^^^
    note: the item is gated behind the `time` feature
       --> /home/josecelano/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.43.0/src/lib.rs:555:1
        |
    555 | / cfg_time! {
    556 | |     pub mod time;
    557 | | }
        | |_^
        = note: this error originates in the macro `cfg_time` (in Nightly builds, run with -Z macro-backtrace for more info)
    help: consider importing this struct
        |
    18  + use std::time::Instant;
        |
    help: if you import `Instant`, refer to it directly
        |
    40  -             last_connection_id_errors_reset: tokio::time::Instant::now(),
    40  +             last_connection_id_errors_reset: Instant::now(),
        |
    
    Some errors have detailed explanations: E0432, E0433.
    For more information about an error, try `rustc --explain E0432`.
    error: could not compile `bittorrent-udp-tracker-core` (lib test) due to 2 previous errors
    error: process didn't exit successfully: `/home/josecelano/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo test --tests --manifest-path /home/josecelano/Documents/git/committer/me/github/torrust/torrust-tracker/packages/udp-tracker-core/Cargo.toml --target-dir /home/josecelano/Documents/git/committer/me/github/torrust/torrust-tracker/target/llvm-cov-target` (exit status: 101)
    

    I've fixed this problem with this PR.

  5. Copilot commented on Sep 1, 2026

    Copilot

    The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: B1A2:FF4D0:93B8BE:A18698:6A971791)

  6. Copilot commented on Sep 1, 2026

    Copilot

    The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: D18C:3ED7E:851332:93C3AA:6A971920)

  7. 11 remaining items

  8. added 4 commits that reference this issue on Oct 7, 2026
  9. josecelano commented on Oct 14, 2026

    @josecelano
    MemberAuthor

    Heads-up from #2521 (merged in PR #2529, 90e8daf75), which changes udp-core files that this issue's plan covers:

    • statistics/services.rs no longer exists. TrackerMetrics and statistics::services::get_metrics() were removed from udp-core and udp-server. Its event-flow docs moved to statistics/mod.rs, with the example fenced rust,ignore. Row 14 of the coverage table (statistics/services.rs) and the runnable-examples note that mentions its doctests no longer apply.
    • UdpCoreStatsRepository was removed from statistics/repository.rs, so a planned test that calls get_metrics_collection() should read through get_stats(), or be dropped if it only exercised the trait.
    • statistics/repository.rs now has a tests module with it_should_contain_the_described_metrics_when_created, which checks that Repository::new() contains the described udp_tracker_core_requests_received_total counter. It restores the check that the deleted service test carried. Row 12's planned repository tests should extend this module rather than duplicate it.
    • The repository's stats field is now private (Make the statistics repositories' metrics lock private #2517, PR refactor: [#2517] make the statistics repositories' metrics lock private #2527); tests read through get_stats().

    Specs: docs/issues/closed/2521-1669-remove-unused-udp-stats-traits/ISSUE.md (archived by PR #2532) and docs/issues/closed/2517-1669-encapsulate-statistics-repository-state/ISSUE.md.

  10. added a commit that references this issue on Oct 15, 2026
  11. added 5 commits that reference this issue on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- Developer -Torrust Improvement ExperienceEasyGood for NewcomersTestingChecking Torrustgood first issueGood for newcomers

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions