Skip to content

Commit

Permalink
dev: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Dec 3, 2023
1 parent 7be2ab5 commit 226ea1a
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 58 deletions.
8 changes: 4 additions & 4 deletions packages/torrent-repository-benchmarks/src/benches/asyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn async_update_one_torrent_in_parallel<T: TRepositoryAsync + Send + S
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 63 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L62-L63

Added lines #L62 - L63 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 67 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L65-L67

Added lines #L65 - L67 were not covered by tests

Expand Down Expand Up @@ -106,7 +106,7 @@ pub async fn async_add_multiple_torrents_in_parallel<T: TRepositoryAsync + Send
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 107 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L106-L107

Added lines #L106 - L107 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 111 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L109-L111

Added lines #L109 - L111 were not covered by tests

Expand Down Expand Up @@ -138,7 +138,7 @@ pub async fn async_update_multiple_torrents_in_parallel<T: TRepositoryAsync + Se
let handles = FuturesUnordered::new();

Check warning on line 138 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L135-L138

Added lines #L135 - L138 were not covered by tests

// Add the torrents/peers to the torrent repository
for info_hash in info_hashes.iter() {
for info_hash in &info_hashes {
torrent_repository

Check warning on line 142 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L141-L142

Added lines #L141 - L142 were not covered by tests
.update_torrent_with_peer_and_get_stats(info_hash, &DEFAULT_PEER)
.await;

Check warning on line 144 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L144

Added line #L144 was not covered by tests
Expand All @@ -157,7 +157,7 @@ pub async fn async_update_multiple_torrents_in_parallel<T: TRepositoryAsync + Se
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 158 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L157-L158

Added lines #L157 - L158 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 162 in packages/torrent-repository-benchmarks/src/benches/asyn.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/asyn.rs#L160-L162

Added lines #L160 - L162 were not covered by tests

Expand Down
19 changes: 10 additions & 9 deletions packages/torrent-repository-benchmarks/src/benches/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::time::Duration;
use clap::Parser;
use futures::stream::FuturesUnordered;
use torrust_tracker::shared::bit_torrent::info_hash::InfoHash;
use torrust_tracker::tracker::torrent::repository::TRepositorySync;
use torrust_tracker::tracker::torrent::repository::Repository;

use crate::args::Args;
use crate::benches::utils::{generate_unique_info_hashes, get_average_and_adjusted_average_from_results, DEFAULT_PEER};

// Simply add one torrent
pub fn add_one_torrent<T: TRepositorySync + Send + Sync + 'static>(samples: usize) -> (Duration, Duration) {
#[must_use]
pub fn add_one_torrent<T: Repository + Send + Sync + 'static>(samples: usize) -> (Duration, Duration) {
let mut results: Vec<Duration> = Vec::with_capacity(samples);

Check warning on line 15 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L14-L15

Added lines #L14 - L15 were not covered by tests

for _ in 0..samples {
Expand All @@ -31,7 +32,7 @@ pub fn add_one_torrent<T: TRepositorySync + Send + Sync + 'static>(samples: usiz
}

Check warning on line 32 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L31-L32

Added lines #L31 - L32 were not covered by tests

// Add one torrent ten thousand times in parallel (depending on the set worker threads)
pub async fn update_one_torrent_in_parallel<T: TRepositorySync + Send + Sync + 'static>(
pub async fn update_one_torrent_in_parallel<T: Repository + Send + Sync + 'static>(
runtime: &tokio::runtime::Runtime,
samples: usize,
) -> (Duration, Duration) {
Expand All @@ -57,7 +58,7 @@ pub async fn update_one_torrent_in_parallel<T: TRepositorySync + Send + Sync + '
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 59 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L58-L59

Added lines #L58 - L59 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 63 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L61-L63

Added lines #L61 - L63 were not covered by tests

Expand All @@ -76,7 +77,7 @@ pub async fn update_one_torrent_in_parallel<T: TRepositorySync + Send + Sync + '
}

Check warning on line 77 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L76-L77

Added lines #L76 - L77 were not covered by tests

// Add ten thousand torrents in parallel (depending on the set worker threads)
pub async fn add_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sync + 'static>(
pub async fn add_multiple_torrents_in_parallel<T: Repository + Send + Sync + 'static>(
runtime: &tokio::runtime::Runtime,
samples: usize,
) -> (Duration, Duration) {
Expand All @@ -99,7 +100,7 @@ pub async fn add_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sync
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 101 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L100-L101

Added lines #L100 - L101 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 105 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L103-L105

Added lines #L103 - L105 were not covered by tests

Expand All @@ -118,7 +119,7 @@ pub async fn add_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sync
}

Check warning on line 119 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L118-L119

Added lines #L118 - L119 were not covered by tests

// Update ten thousand torrents in parallel (depending on the set worker threads)
pub async fn update_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sync + 'static>(
pub async fn update_multiple_torrents_in_parallel<T: Repository + Send + Sync + 'static>(
runtime: &tokio::runtime::Runtime,
samples: usize,
) -> (Duration, Duration) {
Expand All @@ -131,7 +132,7 @@ pub async fn update_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sy
let handles = FuturesUnordered::new();

Check warning on line 132 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L129-L132

Added lines #L129 - L132 were not covered by tests

// Add the torrents/peers to the torrent repository
for info_hash in info_hashes.iter() {
for info_hash in &info_hashes {
torrent_repository.update_torrent_with_peer_and_get_stats(info_hash, &DEFAULT_PEER);

Check warning on line 136 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L135-L136

Added lines #L135 - L136 were not covered by tests
}

Expand All @@ -146,7 +147,7 @@ pub async fn update_multiple_torrents_in_parallel<T: TRepositorySync + Send + Sy
if let Some(sleep_time) = args.sleep {
let start_time = std::time::Instant::now();

Check warning on line 148 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L147-L148

Added lines #L147 - L148 were not covered by tests

while start_time.elapsed().as_nanos() < sleep_time as u128 {}
while start_time.elapsed().as_nanos() < u128::from(sleep_time) {}
}
});

Check warning on line 152 in packages/torrent-repository-benchmarks/src/benches/sync.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/sync.rs#L150-L152

Added lines #L150 - L152 were not covered by tests

Expand Down
7 changes: 7 additions & 0 deletions packages/torrent-repository-benchmarks/src/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ pub const DEFAULT_PEER: Peer = Peer {
event: AnnounceEvent::Started,
};

#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn generate_unique_info_hashes(size: usize) -> Vec<InfoHash> {
let mut result = HashSet::new();

Check warning on line 23 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L22-L23

Added lines #L22 - L23 were not covered by tests

let mut bytes = [0u8; 20];

Check warning on line 25 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L25

Added line #L25 was not covered by tests

#[allow(clippy::cast_possible_truncation)]
for i in 0..size {
bytes[0] = (i & 0xFF) as u8;
bytes[1] = ((i >> 8) & 0xFF) as u8;
Expand All @@ -37,6 +40,7 @@ pub fn generate_unique_info_hashes(size: usize) -> Vec<InfoHash> {
result.into_iter().collect()
}

Check warning on line 41 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L40-L41

Added lines #L40 - L41 were not covered by tests

#[must_use]
pub fn within_acceptable_range(test: &Duration, norm: &Duration) -> bool {
let test_secs = test.as_secs_f64();
let norm_secs = norm.as_secs_f64();

Check warning on line 46 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L44-L46

Added lines #L44 - L46 were not covered by tests
Expand All @@ -51,13 +55,16 @@ pub fn within_acceptable_range(test: &Duration, norm: &Duration) -> bool {
test_secs < upper_limit && test_secs > lower_limit
}

Check warning on line 56 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L55-L56

Added lines #L55 - L56 were not covered by tests

#[must_use]
pub fn get_average_and_adjusted_average_from_results(mut results: Vec<Duration>) -> (Duration, Duration) {

Check warning on line 59 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L59

Added line #L59 was not covered by tests
#[allow(clippy::cast_possible_truncation)]
let average = results.iter().sum::<Duration>() / results.len() as u32;

Check warning on line 61 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L61

Added line #L61 was not covered by tests

results.retain(|result| within_acceptable_range(result, &average));

Check warning on line 63 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L63

Added line #L63 was not covered by tests

let mut adjusted_average = Duration::from_nanos(0);

Check warning on line 65 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L65

Added line #L65 was not covered by tests

#[allow(clippy::cast_possible_truncation)]
if results.len() > 1 {
adjusted_average = results.iter().sum::<Duration>() / results.len() as u32;

Check warning on line 69 in packages/torrent-repository-benchmarks/src/benches/utils.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/benches/utils.rs#L68-L69

Added lines #L68 - L69 were not covered by tests
}
Expand Down
42 changes: 19 additions & 23 deletions packages/torrent-repository-benchmarks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use torrust_torrent_repository_benchmarks::benches::asyn::{
use torrust_torrent_repository_benchmarks::benches::sync::{
add_multiple_torrents_in_parallel, add_one_torrent, update_multiple_torrents_in_parallel, update_one_torrent_in_parallel,
};
use torrust_tracker::tracker::torrent::repository::{
RepositoryAsync, RepositoryAsyncSingle, RepositoryAsyncSync, RepositorySync, RepositorySyncSingle,
};
use torrust_tracker::tracker::torrent::repository::{AsyncSync, RepositoryAsync, RepositoryAsyncSingle, Sync, SyncSingle};

#[allow(clippy::too_many_lines)]
#[allow(clippy::print_literal)]
fn main() {
let args = Args::parse();

Check warning on line 15 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L14-L15

Added lines #L14 - L15 were not covered by tests

Expand Down Expand Up @@ -44,79 +44,75 @@ fn main() {
);

if let Some(true) = args.compare {
println!("");
println!();

Check warning on line 47 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L46-L47

Added lines #L46 - L47 were not covered by tests

println!("std::sync::RwLock<std::collections::BTreeMap<InfoHash, Entry>>");
println!(

Check warning on line 50 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L49-L50

Added lines #L49 - L50 were not covered by tests
"{}: Avg/AdjAvg: {:?}",
"add_one_torrent",
add_one_torrent::<RepositorySyncSingle>(1_000_000)
add_one_torrent::<SyncSingle>(1_000_000)

Check warning on line 53 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L53

Added line #L53 was not covered by tests
);
println!(

Check warning on line 55 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L55

Added line #L55 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_one_torrent_in_parallel",
rt.block_on(update_one_torrent_in_parallel::<RepositorySyncSingle>(&rt, 10))
rt.block_on(update_one_torrent_in_parallel::<SyncSingle>(&rt, 10))

Check warning on line 58 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L58

Added line #L58 was not covered by tests
);
println!(

Check warning on line 60 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L60

Added line #L60 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"add_multiple_torrents_in_parallel",
rt.block_on(add_multiple_torrents_in_parallel::<RepositorySyncSingle>(&rt, 10))
rt.block_on(add_multiple_torrents_in_parallel::<SyncSingle>(&rt, 10))

Check warning on line 63 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L63

Added line #L63 was not covered by tests
);
println!(

Check warning on line 65 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L65

Added line #L65 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_multiple_torrents_in_parallel",
rt.block_on(update_multiple_torrents_in_parallel::<RepositorySyncSingle>(&rt, 10))
rt.block_on(update_multiple_torrents_in_parallel::<SyncSingle>(&rt, 10))

Check warning on line 68 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L68

Added line #L68 was not covered by tests
);

println!("");
println!();

Check warning on line 71 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L71

Added line #L71 was not covered by tests

println!("std::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<std::sync::Mutex<Entry>>>>");
println!(
"{}: Avg/AdjAvg: {:?}",
"add_one_torrent",
add_one_torrent::<RepositorySync>(1_000_000)
);
println!("{}: Avg/AdjAvg: {:?}", "add_one_torrent", add_one_torrent::<Sync>(1_000_000));
println!(

Check warning on line 75 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L73-L75

Added lines #L73 - L75 were not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_one_torrent_in_parallel",
rt.block_on(update_one_torrent_in_parallel::<RepositorySync>(&rt, 10))
rt.block_on(update_one_torrent_in_parallel::<Sync>(&rt, 10))

Check warning on line 78 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L78

Added line #L78 was not covered by tests
);
println!(

Check warning on line 80 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L80

Added line #L80 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"add_multiple_torrents_in_parallel",
rt.block_on(add_multiple_torrents_in_parallel::<RepositorySync>(&rt, 10))
rt.block_on(add_multiple_torrents_in_parallel::<Sync>(&rt, 10))

Check warning on line 83 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L83

Added line #L83 was not covered by tests
);
println!(

Check warning on line 85 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L85

Added line #L85 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_multiple_torrents_in_parallel",
rt.block_on(update_multiple_torrents_in_parallel::<RepositorySync>(&rt, 10))
rt.block_on(update_multiple_torrents_in_parallel::<Sync>(&rt, 10))

Check warning on line 88 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L88

Added line #L88 was not covered by tests
);

println!("");
println!();

Check warning on line 91 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L91

Added line #L91 was not covered by tests

println!("tokio::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<std::sync::Mutex<Entry>>>>");
println!(

Check warning on line 94 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L93-L94

Added lines #L93 - L94 were not covered by tests
"{}: Avg/AdjAvg: {:?}",
"add_one_torrent",
rt.block_on(async_add_one_torrent::<RepositoryAsyncSync>(1_000_000))
rt.block_on(async_add_one_torrent::<AsyncSync>(1_000_000))

Check warning on line 97 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L97

Added line #L97 was not covered by tests
);
println!(

Check warning on line 99 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L99

Added line #L99 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_one_torrent_in_parallel",
rt.block_on(async_update_one_torrent_in_parallel::<RepositoryAsyncSync>(&rt, 10))
rt.block_on(async_update_one_torrent_in_parallel::<AsyncSync>(&rt, 10))

Check warning on line 102 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L102

Added line #L102 was not covered by tests
);
println!(

Check warning on line 104 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L104

Added line #L104 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"add_multiple_torrents_in_parallel",
rt.block_on(async_add_multiple_torrents_in_parallel::<RepositoryAsyncSync>(&rt, 10))
rt.block_on(async_add_multiple_torrents_in_parallel::<AsyncSync>(&rt, 10))

Check warning on line 107 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L107

Added line #L107 was not covered by tests
);
println!(

Check warning on line 109 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L109

Added line #L109 was not covered by tests
"{}: Avg/AdjAvg: {:?}",
"update_multiple_torrents_in_parallel",
rt.block_on(async_update_multiple_torrents_in_parallel::<RepositoryAsyncSync>(&rt, 10))
rt.block_on(async_update_multiple_torrents_in_parallel::<AsyncSync>(&rt, 10))

Check warning on line 112 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L112

Added line #L112 was not covered by tests
);

println!("");
println!();

Check warning on line 115 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L115

Added line #L115 was not covered by tests

println!("tokio::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<tokio::sync::Mutex<Entry>>>>");
println!(

Check warning on line 118 in packages/torrent-repository-benchmarks/src/main.rs

View check run for this annotation

Codecov / codecov/patch

packages/torrent-repository-benchmarks/src/main.rs#L117-L118

Added lines #L117 - L118 were not covered by tests
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(async_fn_in_trait)]
#![feature(return_position_impl_trait_in_trait)]
//! **Torrust Tracker** is a modern and feature-rich (private) [`BitTorrent`](https://www.bittorrent.org/) tracker.
//!
Expand Down
9 changes: 6 additions & 3 deletions src/tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ use torrust_tracker_primitives::TrackerMode;
use self::auth::Key;
use self::error::Error;
use self::peer::Peer;
use self::torrent::repository::{RepositoryAsyncSingle, TRepositoryAsync};
use crate::shared::bit_torrent::info_hash::InfoHash;
use crate::tracker::databases::Database;
use crate::tracker::torrent::repository::{RepositoryAsyncSingle, TRepositoryAsync};
use crate::tracker::torrent::{SwarmMetadata, SwarmStats};

/// The domain layer tracker service.
Expand Down Expand Up @@ -727,7 +727,7 @@ impl Tracker {
if self.config.persistent_torrent_completed_stat && stats_updated {
let database = self.database.clone();
let completed = stats.completed;
let info_hash = info_hash.clone();
let info_hash = *info_hash;

drop(database.save_persistent_torrent(&info_hash, completed).await);
}
Expand All @@ -739,6 +739,9 @@ impl Tracker {
/// [`TorrentsMetrics`]
///
/// # Context: Tracker
///
/// # Panics
/// Panics if unable to get the torrent metrics.
pub async fn get_torrents_metrics(&self) -> TorrentsMetrics {
let arc_torrents_metrics = Arc::new(tokio::sync::Mutex::new(TorrentsMetrics {
seeders: 0,
Expand Down Expand Up @@ -786,7 +789,7 @@ impl Tracker {
if self.config.remove_peerless_torrents {
let mut cleaned_torrents_map: BTreeMap<InfoHash, torrent::Entry> = BTreeMap::new();

Check warning on line 790 in src/tracker/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/tracker/mod.rs#L790

Added line #L790 was not covered by tests

for (info_hash, torrent_entry) in torrents_lock.iter_mut() {
for (info_hash, torrent_entry) in &mut *torrents_lock {

Check warning on line 792 in src/tracker/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/tracker/mod.rs#L792

Added line #L792 was not covered by tests
torrent_entry.remove_inactive_peers(self.config.max_peer_timeout);

if torrent_entry.peers.is_empty() {

Check warning on line 795 in src/tracker/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/tracker/mod.rs#L795

Added line #L795 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/tracker/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub async fn get_torrents(tracker: Arc<Tracker>, pagination: &Pagination) -> Vec
seeders: u64::from(seeders),
completed: u64::from(completed),
leechers: u64::from(leechers),
})
});
}

basic_infos
Expand Down
Loading

0 comments on commit 226ea1a

Please sign in to comment.