Skip to content

Overhaul core Tracker: add units tests to the new tracker-core package #1226

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
7 tasks done
Tracked by #1181
josecelano opened this issue Jan 29, 2025 · 4 comments
Closed
7 tasks done
Tracked by #1181
Assignees
Labels
- Developer - Torrust Improvement Experience EPIC Contains several subissues Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust

Comments

@josecelano
Copy link
Member

josecelano commented Jan 29, 2025

Parent issue: #1181

After extracting the new package I want to review the tests. We had a lot of high-level tests because It was very hard to unit test the old core::Tracker. Now it should be easier to write unit tests for the package.

Sub-tasks

@josecelano josecelano added - Developer - Torrust Improvement Experience Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust labels Jan 29, 2025
@josecelano josecelano self-assigned this Jan 29, 2025
@josecelano josecelano mentioned this issue Jan 29, 2025
26 tasks
@josecelano
Copy link
Member Author

josecelano commented Feb 3, 2025

The code coverage report for only the bittorrent-tracker-core package:

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

The current state before starting adding tests:

Filename                                                                    Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
packages/tracker-core/src/announce_handler.rs                                      32                 2    93.75%         380                15    96.05%           0                 0         -
packages/tracker-core/src/authentication/handler.rs                                28                 1    96.43%         203                35    82.76%           0                 0         -
packages/tracker-core/src/authentication/key/mod.rs                                18                 3    83.33%         124                12    90.32%           0                 0         -
packages/tracker-core/src/authentication/key/repository/in_memory.rs               10                 2    80.00%          25                 5    80.00%           0                 0         -
packages/tracker-core/src/authentication/key/repository/persisted.rs                4                 0   100.00%          17                 0   100.00%           0                 0         -
packages/tracker-core/src/authentication/mod.rs                                    19                 0   100.00%         201                 0   100.00%           0                 0         -
packages/tracker-core/src/authentication/service.rs                                 9                 0   100.00%          53                 2    96.23%           0                 0         -
packages/tracker-core/src/core_tests.rs                                             9                 0   100.00%          62                 0   100.00%           0                 0         -
packages/tracker-core/src/databases/driver.rs                                       1                 0   100.00%           9                 2    77.78%           0                 0         -
packages/tracker-core/src/databases/error.rs                                        4                 4     0.00%          31                31     0.00%           0                 0         -
packages/tracker-core/src/databases/mod.rs                                          2                 0   100.00%           6                 0   100.00%           0                 0         -
packages/tracker-core/src/databases/mysql.rs                                       31                31     0.00%         189               189     0.00%           0                 0         -
packages/tracker-core/src/databases/setup.rs                                        1                 0   100.00%           6                 1    83.33%           0                 0         -
packages/tracker-core/src/databases/sqlite.rs                                      34                18    47.06%         208                81    61.06%           0                 0         -
packages/tracker-core/src/error.rs                                                  1                 1     0.00%           5                 5     0.00%           0                 0         -
packages/tracker-core/src/lib.rs                                                    7                 0   100.00%         120                 0   100.00%           0                 0         -
packages/tracker-core/src/peer_tests.rs                                             1                 0   100.00%          35                 0   100.00%           0                 0         -
packages/tracker-core/src/scrape_handler.rs                                         8                 0   100.00%          83                 0   100.00%           0                 0         -
packages/tracker-core/src/torrent/manager.rs                                        3                 1    66.67%          28                11    60.71%           0                 0         -
packages/tracker-core/src/torrent/repository/in_memory.rs                          27                 2    92.59%         298                 9    96.98%           0                 0         -
packages/tracker-core/src/torrent/repository/persisted.rs                           3                 0   100.00%          11                 0   100.00%           0                 0         -
packages/tracker-core/src/torrent/services.rs                                      20                 2    90.00%         323                14    95.67%           0                 0         -
packages/tracker-core/src/whitelist/authorization.rs                                8                 0   100.00%          46                 0   100.00%           0                 0         -
packages/tracker-core/src/whitelist/manager.rs                                     21                 3    85.71%         113                 7    93.81%           0                 0         -
packages/tracker-core/src/whitelist/mod.rs                                          4                 0   100.00%          33                 0   100.00%           0                 0         -
packages/tracker-core/src/whitelist/repository/in_memory.rs                        16                 0   100.00%          85                 0   100.00%           0                 0         -
packages/tracker-core/src/whitelist/repository/persisted.rs                         4                 0   100.00%          24                 2    91.67%           0                 0         -
packages/tracker-core/src/whitelist/setup.rs                                        1                 0   100.00%           7                 0   100.00%           0                 0         -
packages/tracker-core/src/whitelist/whitelist_tests.rs                              2                 0   100.00%          11                 0   100.00%           0                 0         -

I will add more unit tests to the package.

@josecelano
Copy link
Member Author

josecelano commented Feb 11, 2025

TORRUST_TRACKER_CORE_RUN_MYSQL_DRIVER_TEST=true cargo llvm-cov --package bittorrent-tracker-core
Filename                                                           Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clock/src/clock/mod.rs                                                   2                 0   100.00%           2                 0   100.00%           6                 0   100.00%           0                 0         -
clock/src/clock/stopped/mod.rs                                          31                13    58.06%          15                 5    66.67%          59                21    64.41%           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                 2    33.33%           3                 2    33.33%          13                 6    53.85%           0                 0         -
configuration/src/lib.rs                                                30                18    40.00%          19                 7    63.16%          90                41    54.44%           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                 3    57.14%           5                 2    60.00%          26                 9    65.38%           0                 0         -
primitives/src/core.rs                                                   8                 5    37.50%           4                 1    75.00%          17                 7    58.82%           0                 0         -
primitives/src/pagination.rs                                            13                10    23.08%           4                 1    75.00%          21                 9    57.14%           0                 0         -
primitives/src/peer.rs                                                  72                48    33.33%          42                28    33.33%         211               153    27.49%           0                 0         -
primitives/src/swarm_metadata.rs                                         1                 0   100.00%           1                 0   100.00%           3                 0   100.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                19    20.83%          11                 6    45.45%         124                53    57.26%           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                 1    88.89%           9                 1    88.89%          29                 3    89.66%           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                 5    78.26%          13                 3    76.92%          53                14    73.58%           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                 4    82.61%           9                 0   100.00%          54                 7    87.04%           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                89    29.37%          42                30    28.57%         228               158    30.70%           0                 0         -
tracker-core/src/announce_handler.rs                                    95                 4    95.79%          45                 0   100.00%         536                 1    99.81%           0                 0         -
tracker-core/src/authentication/handler.rs                             158                 9    94.30%          52                 0   100.00%         583                 0   100.00%           0                 0         -
tracker-core/src/authentication/key/mod.rs                              36                 3    91.67%          12                 0   100.00%          99                 0   100.00%           0                 0         -
tracker-core/src/authentication/key/peer_key.rs                         47                 1    97.87%          19                 0   100.00%         115                 1    99.13%           0                 0         -
tracker-core/src/authentication/key/repository/in_memory.rs             51                 0   100.00%          20                 0   100.00%         169                 0   100.00%           0                 0         -
tracker-core/src/authentication/key/repository/persisted.rs             24                 2    91.67%           8                 0   100.00%          77                 0   100.00%           0                 0         -
tracker-core/src/authentication/mod.rs                                  67                 0   100.00%          19                 0   100.00%         219                 0   100.00%           0                 0         -
tracker-core/src/authentication/service.rs                              52                 0   100.00%          20                 0   100.00%         268                 0   100.00%           0                 0         -
tracker-core/src/core_tests.rs                                          17                 0   100.00%          17                 0   100.00%         133                 0   100.00%           0                 0         -
tracker-core/src/databases/driver/mod.rs                                47                 5    89.36%          17                 0   100.00%         143                 4    97.20%           0                 0         -
tracker-core/src/databases/driver/mysql.rs                             195                40    79.49%          45                13    71.11%         288                18    93.75%           0                 0         -
tracker-core/src/databases/driver/sqlite.rs                            222                57    74.32%          37                13    64.86%         234                35    85.04%           0                 0         -
tracker-core/src/databases/error.rs                                     23                 5    78.26%           8                 1    87.50%          52                 7    86.54%           0                 0         -
tracker-core/src/databases/mod.rs                                        5                 1    80.00%           2                 0   100.00%           4                 0   100.00%           0                 0         -
tracker-core/src/databases/setup.rs                                      6                 1    83.33%           1                 0   100.00%           6                 1    83.33%           0                 0         -
tracker-core/src/error.rs                                               12                 4    66.67%           4                 0   100.00%          53                 4    92.45%           0                 0         -
tracker-core/src/lib.rs                                                 13                 0   100.00%           7                 0   100.00%         120                 0   100.00%           0                 0         -
tracker-core/src/peer_tests.rs                                           2                 0   100.00%           1                 0   100.00%          35                 0   100.00%           0                 0         -
tracker-core/src/scrape_handler.rs                                      22                 0   100.00%           8                 0   100.00%          83                 0   100.00%           0                 0         -
tracker-core/src/torrent/manager.rs                                     22                 1    95.45%          10                 0   100.00%         130                 0   100.00%           0                 0         -
tracker-core/src/torrent/repository/in_memory.rs                        89                 1    98.88%          63                 0   100.00%         866                 1    99.88%           0                 0         -
tracker-core/src/torrent/repository/persisted.rs                         8                 0   100.00%           6                 0   100.00%          44                 0   100.00%           0                 0         -
tracker-core/src/torrent/services.rs                                    43                 0   100.00%          24                 0   100.00%         373                 0   100.00%           0                 0         -
tracker-core/src/whitelist/authorization.rs                             33                 0   100.00%          16                 0   100.00%         100                 0   100.00%           0                 0         -
tracker-core/src/whitelist/manager.rs                                   39                 3    92.31%          15                 0   100.00%         109                 0   100.00%           0                 0         -
tracker-core/src/whitelist/mod.rs                                       13                 0   100.00%           4                 0   100.00%          33                 0   100.00%           0                 0         -
tracker-core/src/whitelist/repository/in_memory.rs                      28                 0   100.00%          16                 0   100.00%          85                 0   100.00%           0                 0         -
tracker-core/src/whitelist/repository/persisted.rs                      33                 4    87.88%          10                 0   100.00%          79                 0   100.00%           0                 0         -
tracker-core/src/whitelist/setup.rs                                      1                 0   100.00%           1                 0   100.00%           7                 0   100.00%           0                 0         -
tracker-core/src/whitelist/whitelist_tests.rs                            3                 0   100.00%           2                 0   100.00%          11                 0   100.00%           0                 0         -

@josecelano
Copy link
Member Author

Image

@josecelano
Copy link
Member Author

josecelano commented Feb 11, 2025

I didn't reach 100% line coverage:

Image

But the critical functionality is covered. I didn't add tests for database errors, for example:

  • Try to add a key when the keys table is missing.
  • Same for all the methods.

cc @da2ce7

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
- Developer - Torrust Improvement Experience EPIC Contains several subissues Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust
Projects
None yet
Development

No branches or pull requests

1 participant