Skip to content

Commit bc1f8cc

Browse files
committed
fix(lint/clippy): resolve pedantic duration and style violations
1 parent fa3b491 commit bc1f8cc

10 files changed

Lines changed: 19 additions & 17 deletions

File tree

packages/axum-rest-tracker-api-server/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ pub struct Launcher {
220220
impl std::fmt::Display for Launcher {
221221
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
222222
if self.tls.is_some() {
223-
write!(f, "(with socket): {}, using TLS", self.bind_to,)
223+
write!(f, "(with socket): {}, using TLS", self.bind_to)
224224
} else {
225-
write!(f, "(with socket): {}, without TLS", self.bind_to,)
225+
write!(f, "(with socket): {}, without TLS", self.bind_to)
226226
}
227227
}
228228
}

packages/http-tracker-core/benches/http_tracker_core_benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn announce_once(c: &mut Criterion) {
1212
let mut group = c.benchmark_group("http_tracker_handle_announce_once");
1313

1414
group.warm_up_time(Duration::from_millis(500));
15-
group.measurement_time(Duration::from_millis(1000));
15+
group.measurement_time(Duration::from_secs(1));
1616

1717
group.bench_function("handle_announce_data", |b| {
1818
b.iter(|| sync::return_announce_data_once(100));

packages/torrent-repository-benchmarking/benches/repository_benchmark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn add_one_torrent(c: &mut Criterion) {
1717
let mut group = c.benchmark_group("add_one_torrent");
1818

1919
group.warm_up_time(Duration::from_millis(500));
20-
group.measurement_time(Duration::from_millis(1000));
20+
group.measurement_time(Duration::from_secs(1));
2121

2222
group.bench_function("RwLockStd", |b| {
2323
b.iter_custom(sync::add_one_torrent::<TorrentsRwLockStd, _>);
@@ -74,7 +74,7 @@ fn add_multiple_torrents_in_parallel(c: &mut Criterion) {
7474
//group.sample_size(10);
7575

7676
group.warm_up_time(Duration::from_millis(500));
77-
group.measurement_time(Duration::from_millis(1000));
77+
group.measurement_time(Duration::from_secs(1));
7878

7979
group.bench_function("RwLockStd", |b| {
8080
b.to_async(&rt)
@@ -138,7 +138,7 @@ fn update_one_torrent_in_parallel(c: &mut Criterion) {
138138
//group.sample_size(10);
139139

140140
group.warm_up_time(Duration::from_millis(500));
141-
group.measurement_time(Duration::from_millis(1000));
141+
group.measurement_time(Duration::from_secs(1));
142142

143143
group.bench_function("RwLockStd", |b| {
144144
b.to_async(&rt)
@@ -202,7 +202,7 @@ fn update_multiple_torrents_in_parallel(c: &mut Criterion) {
202202
//group.sample_size(10);
203203

204204
group.warm_up_time(Duration::from_millis(500));
205-
group.measurement_time(Duration::from_millis(1000));
205+
group.measurement_time(Duration::from_secs(1));
206206

207207
group.bench_function("RwLockStd", |b| {
208208
b.to_async(&rt)

packages/torrent-repository-benchmarking/tests/entry/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
2-
use std::ops::Sub;
32
use std::time::Duration;
43

54
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes};
@@ -430,7 +429,9 @@ async fn it_should_remove_inactive_peers_beyond_cutoff(
430429
let now = clock::Working::now();
431430
clock::Stopped::local_set(&now);
432431

433-
peer.updated = now.sub(EXPIRE);
432+
peer.updated = now
433+
.checked_sub(EXPIRE)
434+
.expect("it_should_remove_inactive_peers_beyond_cutoff: EXPIRE must not exceed now");
434435

435436
torrent.upsert_peer(&peer).await;
436437

packages/torrent-repository-benchmarking/tests/repository/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ async fn it_should_remove_inactive_peers(
526526
repo: Repo,
527527
#[case] entries: Entries,
528528
) {
529-
use std::ops::Sub as _;
530529
use std::time::Duration;
531530

532531
use torrust_tracker_clock::clock::stopped::Stopped as _;
@@ -556,7 +555,9 @@ async fn it_should_remove_inactive_peers(
556555
let now = clock::Working::now();
557556
clock::Stopped::local_set(&now);
558557

559-
peer.updated = now.sub(EXPIRE);
558+
peer.updated = now
559+
.checked_sub(EXPIRE)
560+
.expect("it_should_remove_inactive_peers_beyond_cutoff: EXPIRE must not exceed now");
560561
}
561562

562563
// Insert the infohash and peer into the repository

packages/tracker-client/src/udp/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub async fn check(service_binding: &ServiceBinding) -> Result<String, String> {
256256
}
257257
};
258258

259-
let sleep = time::sleep(Duration::from_millis(2000));
259+
let sleep = time::sleep(Duration::from_secs(2));
260260
tokio::pin!(sleep);
261261

262262
tokio::select! {

packages/udp-tracker-core/benches/udp_tracker_core_benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::helpers::sync;
99
fn bench_connect_once(c: &mut Criterion) {
1010
let mut group = c.benchmark_group("udp_tracker/connect_once");
1111
group.warm_up_time(Duration::from_millis(500));
12-
group.measurement_time(Duration::from_millis(1000));
12+
group.measurement_time(Duration::from_secs(1));
1313

1414
group.bench_function("connect_once", |b| {
1515
b.iter(|| sync::connect_once(100));

packages/udp-tracker-server/src/server/launcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Launcher {
5454
panic!("it should not use udp if using authentication");
5555
}
5656

57-
let socket = tokio::time::timeout(Duration::from_millis(5000), BoundSocket::new(bind_to))
57+
let socket = tokio::time::timeout(Duration::from_secs(5), BoundSocket::new(bind_to))
5858
.await
5959
.expect("it should bind to the socket within five seconds");
6060

packages/udp-tracker-server/src/statistics/repository.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ mod tests {
330330

331331
// Calculate new average with processing time of 2000ns
332332
// This will increment the processed requests counter from 0 to 1
333-
let processing_time = Duration::from_nanos(2000);
333+
let processing_time = Duration::from_micros(2);
334334
let new_avg = repo
335335
.recalculate_udp_avg_processing_time_ns(processing_time, &connect_labels, now)
336336
.await;
@@ -417,7 +417,7 @@ mod tests {
417417
let now = CurrentClock::now();
418418

419419
// Test with zero connections (should not panic, should handle division by zero)
420-
let processing_time = Duration::from_nanos(1000);
420+
let processing_time = Duration::from_micros(1);
421421

422422
let connect_labels = LabelSet::from([("request_kind", "connect")]);
423423
let connect_avg = repo

packages/udp-tracker-server/tests/server/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn send_connection_request(transaction_id: TransactionId, client: &UdpTrac
3232

3333
match response {
3434
Response::Connect(connect_response) => connect_response.connection_id,
35-
_ => panic!("error connecting to udp server {:?}", response),
35+
_ => panic!("error connecting to udp server {response:?}"),
3636
}
3737
}
3838

0 commit comments

Comments
 (0)