Skip to content

Commit b8e0803

Browse files
committed
Merge #1216: Overhaul core Tracker: remove complexity (type_complexity)
8f02fb9 refactor: [#1215] instantiate only needed services (Jose Celano) Pull request description: Overhaul core Tracker: remove complexity. ACKs for top commit: josecelano: ACK 8f02fb9 Tree-SHA512: a2878294aaa7ce9f33c7a945c4aa737035e5c030d9610632cc2fd4e1819284680c619d87180356ec71c28ccc1b71969efae958f9120a3aab426f7aa853c08680
2 parents 74b04c8 + 8f02fb9 commit b8e0803

File tree

9 files changed

+359
-702
lines changed

9 files changed

+359
-702
lines changed

src/app_test.rs

-62
This file was deleted.

src/core/services/statistics/mod.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ mod tests {
117117
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
118118
use torrust_tracker_test_helpers::configuration;
119119

120-
use crate::app_test::initialize_tracker_dependencies;
121120
use crate::core::services::statistics::{self, get_metrics, TrackerMetrics};
121+
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
122122
use crate::core::{self};
123123
use crate::servers::udp::server::banning::BanService;
124124
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;
@@ -131,19 +131,9 @@ mod tests {
131131
async fn the_statistics_service_should_return_the_tracker_metrics() {
132132
let config = tracker_configuration();
133133

134-
let (
135-
_database,
136-
_in_memory_whitelist,
137-
_whitelist_authorization,
138-
_authentication_service,
139-
in_memory_torrent_repository,
140-
_db_torrent_repository,
141-
_torrents_manager,
142-
) = initialize_tracker_dependencies(&config);
143-
134+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
144135
let (_stats_event_sender, stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
145136
let stats_repository = Arc::new(stats_repository);
146-
147137
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
148138

149139
let tracker_metrics = get_metrics(

src/core/services/torrent.rs

+7-48
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,10 @@ pub async fn get_torrents(
112112
#[cfg(test)]
113113
mod tests {
114114
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
115-
use std::sync::Arc;
116115

117116
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
118-
use torrust_tracker_configuration::Configuration;
119117
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
120118

121-
use crate::app_test::initialize_tracker_dependencies;
122-
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
123-
124-
fn initialize_in_memory_torrent_repository(config: &Configuration) -> Arc<InMemoryTorrentRepository> {
125-
let (
126-
_database,
127-
_in_memory_whitelist,
128-
_whitelist_authorization,
129-
_authentication_service,
130-
in_memory_torrent_repository,
131-
_db_torrent_repository,
132-
_torrents_manager,
133-
) = initialize_tracker_dependencies(config);
134-
135-
in_memory_torrent_repository
136-
}
137-
138119
fn sample_peer() -> peer::Peer {
139120
peer::Peer {
140121
peer_id: PeerId(*b"-qB00000000000000000"),
@@ -153,17 +134,11 @@ mod tests {
153134
use std::sync::Arc;
154135

155136
use bittorrent_primitives::info_hash::InfoHash;
156-
use torrust_tracker_configuration::Configuration;
157-
use torrust_tracker_test_helpers::configuration;
158137

159-
use crate::core::services::torrent::tests::{initialize_in_memory_torrent_repository, sample_peer};
138+
use crate::core::services::torrent::tests::sample_peer;
160139
use crate::core::services::torrent::{get_torrent_info, Info};
161140
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
162141

163-
pub fn tracker_configuration() -> Configuration {
164-
configuration::ephemeral()
165-
}
166-
167142
#[tokio::test]
168143
async fn should_return_none_if_the_tracker_does_not_have_the_torrent() {
169144
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
@@ -179,9 +154,7 @@ mod tests {
179154

180155
#[tokio::test]
181156
async fn should_return_the_torrent_info_if_the_tracker_has_the_torrent() {
182-
let config = tracker_configuration();
183-
184-
let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config);
157+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
185158

186159
let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
187160
let info_hash = InfoHash::from_str(&hash).unwrap();
@@ -210,17 +183,11 @@ mod tests {
210183
use std::sync::Arc;
211184

212185
use bittorrent_primitives::info_hash::InfoHash;
213-
use torrust_tracker_configuration::Configuration;
214-
use torrust_tracker_test_helpers::configuration;
215186

216-
use crate::core::services::torrent::tests::{initialize_in_memory_torrent_repository, sample_peer};
187+
use crate::core::services::torrent::tests::sample_peer;
217188
use crate::core::services::torrent::{get_torrents_page, BasicInfo, Pagination};
218189
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
219190

220-
pub fn tracker_configuration() -> Configuration {
221-
configuration::ephemeral()
222-
}
223-
224191
#[tokio::test]
225192
async fn should_return_an_empty_result_if_the_tracker_does_not_have_any_torrent() {
226193
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
@@ -232,9 +199,7 @@ mod tests {
232199

233200
#[tokio::test]
234201
async fn should_return_a_summarized_info_for_all_torrents() {
235-
let config = tracker_configuration();
236-
237-
let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config);
202+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
238203

239204
let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
240205
let info_hash = InfoHash::from_str(&hash).unwrap();
@@ -256,9 +221,7 @@ mod tests {
256221

257222
#[tokio::test]
258223
async fn should_allow_limiting_the_number_of_torrents_in_the_result() {
259-
let config = tracker_configuration();
260-
261-
let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config);
224+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
262225

263226
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
264227
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
@@ -279,9 +242,7 @@ mod tests {
279242

280243
#[tokio::test]
281244
async fn should_allow_using_pagination_in_the_result() {
282-
let config = tracker_configuration();
283-
284-
let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config);
245+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
285246

286247
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
287248
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
@@ -311,9 +272,7 @@ mod tests {
311272

312273
#[tokio::test]
313274
async fn should_return_torrents_ordered_by_info_hash() {
314-
let config = tracker_configuration();
315-
316-
let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config);
275+
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
317276

318277
let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
319278
let info_hash1 = InfoHash::from_str(&hash1).unwrap();

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@
491491
use torrust_tracker_clock::clock;
492492

493493
pub mod app;
494-
pub mod app_test;
495494
pub mod bootstrap;
496495
pub mod console;
497496
pub mod container;

0 commit comments

Comments
 (0)