From 01a07b7c91e42e194d04b7ebbf166523ad066f93 Mon Sep 17 00:00:00 2001 From: Mees Delzenne Date: Sat, 9 Dec 2023 21:25:50 +0100 Subject: [PATCH] Fix clippy warnings in tests (#3101) --- lib/benches/sdb_benches/lib/mod.rs | 6 ++--- .../sdb_benches/lib/routines/create.rs | 2 +- lib/benches/sdb_benches/lib/routines/mod.rs | 2 -- lib/benches/sdb_benches/lib/routines/read.rs | 2 +- lib/benches/sdb_benches/mod.rs | 2 +- lib/benches/sdb_benches/sdk/mod.rs | 6 ++--- .../sdb_benches/sdk/routines/create.rs | 2 +- lib/benches/sdb_benches/sdk/routines/mod.rs | 6 ++--- lib/benches/sdb_benches/sdk/routines/read.rs | 2 +- lib/src/idx/trees/mtree.rs | 26 +++++++++---------- lib/src/kvs/tests/ndlq.rs | 2 +- lib/src/kvs/tests/nq.rs | 4 +-- lib/src/kvs/tests/tblq.rs | 2 +- 13 files changed, 30 insertions(+), 34 deletions(-) diff --git a/lib/benches/sdb_benches/lib/mod.rs b/lib/benches/sdb_benches/lib/mod.rs index bc28eb69..ca6a10fc 100644 --- a/lib/benches/sdb_benches/lib/mod.rs +++ b/lib/benches/sdb_benches/lib/mod.rs @@ -44,15 +44,15 @@ pub(super) async fn init(target: &str) { } pub(super) fn benchmark_group(c: &mut Criterion, target: String) { - let num_ops = super::NUM_OPS.clone(); + let num_ops = *super::NUM_OPS; let runtime = super::rt(); runtime.block_on(async { init(&target).await }); let mut group = c.benchmark_group(target); - group.measurement_time(Duration::from_secs(super::DURATION_SECS.clone())); - group.sample_size(super::SAMPLE_SIZE.clone()); + group.measurement_time(Duration::from_secs(*super::DURATION_SECS)); + group.sample_size(*super::SAMPLE_SIZE); group.throughput(Throughput::Elements(1)); group.bench_function("reads", |b| { diff --git a/lib/benches/sdb_benches/lib/routines/create.rs b/lib/benches/sdb_benches/lib/routines/create.rs index a9990618..e961de2b 100644 --- a/lib/benches/sdb_benches/lib/routines/create.rs +++ b/lib/benches/sdb_benches/lib/routines/create.rs @@ -13,7 +13,7 @@ impl Create { pub fn new(runtime: &'static Runtime) -> Self { Self { runtime, - table_name: format!("table_{}", Id::rand().to_string()), + table_name: format!("table_{}", Id::rand()), } } } diff --git a/lib/benches/sdb_benches/lib/routines/mod.rs b/lib/benches/sdb_benches/lib/routines/mod.rs index b16cdd04..c7b5f82b 100644 --- a/lib/benches/sdb_benches/lib/routines/mod.rs +++ b/lib/benches/sdb_benches/lib/routines/mod.rs @@ -32,8 +32,6 @@ pub(super) fn bench_routine( { // Run the runtime and return the duration, accounting for the number of operations on each run b.iter_custom(|iters| { - let num_ops = num_ops.clone(); - // Total time spent running the actual benchmark run for all iterations let mut total = std::time::Duration::from_secs(0); let session = Session::owner().with_ns("test").with_db("test"); diff --git a/lib/benches/sdb_benches/lib/routines/read.rs b/lib/benches/sdb_benches/lib/routines/read.rs index 0b1e364c..572eda1a 100644 --- a/lib/benches/sdb_benches/lib/routines/read.rs +++ b/lib/benches/sdb_benches/lib/routines/read.rs @@ -13,7 +13,7 @@ impl Read { pub fn new(runtime: &'static Runtime) -> Self { Self { runtime, - table_name: format!("table_{}", Id::rand().to_string()), + table_name: format!("table_{}", Id::rand()), } } } diff --git a/lib/benches/sdb_benches/mod.rs b/lib/benches/sdb_benches/mod.rs index 5a56857d..5b9dd5e4 100644 --- a/lib/benches/sdb_benches/mod.rs +++ b/lib/benches/sdb_benches/mod.rs @@ -19,7 +19,7 @@ static RUNTIME: OnceLock = OnceLock::new(); fn rt() -> &'static Runtime { RUNTIME.get_or_init(|| { tokio::runtime::Builder::new_multi_thread() - .worker_threads(WORKER_THREADS.clone()) + .worker_threads(*WORKER_THREADS) .enable_all() .build() .unwrap() diff --git a/lib/benches/sdb_benches/sdk/mod.rs b/lib/benches/sdb_benches/sdk/mod.rs index 29ffae2d..723451d4 100644 --- a/lib/benches/sdb_benches/sdk/mod.rs +++ b/lib/benches/sdb_benches/sdk/mod.rs @@ -48,15 +48,15 @@ pub(super) async fn init(target: &str) { } pub(super) fn benchmark_group(c: &mut Criterion, target: String) { - let num_ops = super::NUM_OPS.clone(); + let num_ops = *super::NUM_OPS; let runtime = super::rt(); runtime.block_on(async { init(&target).await }); let mut group = c.benchmark_group(target); - group.measurement_time(Duration::from_secs(super::DURATION_SECS.clone())); - group.sample_size(super::SAMPLE_SIZE.clone()); + group.measurement_time(Duration::from_secs(*super::DURATION_SECS)); + group.sample_size(*super::SAMPLE_SIZE); group.throughput(Throughput::Elements(1)); group.bench_function("reads", |b| { diff --git a/lib/benches/sdb_benches/sdk/routines/create.rs b/lib/benches/sdb_benches/sdk/routines/create.rs index 760ea999..ac625251 100644 --- a/lib/benches/sdb_benches/sdk/routines/create.rs +++ b/lib/benches/sdb_benches/sdk/routines/create.rs @@ -12,7 +12,7 @@ impl Create { pub fn new(runtime: &'static Runtime) -> Self { Self { runtime, - table_name: format!("table_{}", Id::rand().to_string()), + table_name: format!("table_{}", Id::rand()), } } } diff --git a/lib/benches/sdb_benches/sdk/routines/mod.rs b/lib/benches/sdb_benches/sdk/routines/mod.rs index c565bea7..c15941ba 100644 --- a/lib/benches/sdb_benches/sdk/routines/mod.rs +++ b/lib/benches/sdb_benches/sdk/routines/mod.rs @@ -28,17 +28,15 @@ pub(super) fn bench_routine( { // Run the runtime and return the duration, accounting for the number of operations on each run b.iter_custom(|iters| { - let num_ops = num_ops.clone(); - // Total time spent running the actual benchmark run for all iterations let mut total = std::time::Duration::from_secs(0); for _ in 0..iters { // Setup - routine.setup(db, num_ops.clone()); + routine.setup(db, num_ops); // Run and time the routine let now = std::time::Instant::now(); - routine.run(db, num_ops.clone()); + routine.run(db, num_ops); total += now.elapsed(); // Cleanup the database diff --git a/lib/benches/sdb_benches/sdk/routines/read.rs b/lib/benches/sdb_benches/sdk/routines/read.rs index 8e6e9ea5..a652faa7 100644 --- a/lib/benches/sdb_benches/sdk/routines/read.rs +++ b/lib/benches/sdb_benches/sdk/routines/read.rs @@ -12,7 +12,7 @@ impl Read { pub fn new(runtime: &'static Runtime) -> Self { Self { runtime, - table_name: format!("table_{}", Id::rand().to_string()), + table_name: format!("table_{}", Id::rand()), } } } diff --git a/lib/src/idx/trees/mtree.rs b/lib/src/idx/trees/mtree.rs index 2ae026f9..13702164 100644 --- a/lib/src/idx/trees/mtree.rs +++ b/lib/src/idx/trees/mtree.rs @@ -2041,7 +2041,7 @@ mod tests { let mut c = 0; for (doc_id, obj) in collection.as_ref() { { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Write).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Write).await; let mut s = s.lock().await; t.insert(&mut tx, &mut s, obj.as_ref().clone(), *doc_id).await?; finish_operation(tx, s, true).await?; @@ -2049,9 +2049,9 @@ mod tests { } c += 1; { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Traversal).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Traversal).await; let mut s = s.lock().await; - let p = check_tree_properties(&mut tx, &mut s, &t).await?; + let p = check_tree_properties(&mut tx, &mut s, t).await?; assert_eq!(p.doc_count, c); } } @@ -2065,7 +2065,7 @@ mod tests { ) -> Result, Error> { let mut map = HashMap::with_capacity(collection.as_ref().len()); { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Write).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Write).await; let mut s = s.lock().await; for (doc_id, obj) in collection.as_ref() { t.insert(&mut tx, &mut s, obj.as_ref().clone(), *doc_id).await?; @@ -2074,9 +2074,9 @@ mod tests { finish_operation(tx, s, true).await?; } { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Traversal).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Traversal).await; let mut s = s.lock().await; - check_tree_properties(&mut tx, &mut s, &t).await?; + check_tree_properties(&mut tx, &mut s, t).await?; } Ok(map) } @@ -2108,13 +2108,13 @@ mod tests { { let (s, mut tx) = new_operation(ds, TreeStoreType::Traversal).await; let mut s = s.lock().await; - check_tree_properties(&mut tx, &mut s, &t).await?; + check_tree_properties(&mut tx, &mut s, t).await?; } } - let (s, mut tx) = new_operation(&ds, TreeStoreType::Traversal).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Traversal).await; let mut s = s.lock().await; - check_tree_properties(&mut tx, &mut s, &t).await?.check(0, 0, None, None, 0, 0); + check_tree_properties(&mut tx, &mut s, t).await?.check(0, 0, None, None, 0, 0); Ok(()) } @@ -2123,7 +2123,7 @@ mod tests { t: &mut MTree, collection: &TestCollection, ) -> Result<(), Error> { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Read).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Read).await; let mut s = s.lock().await; let max_knn = 20.max(collection.as_ref().len()); for (doc_id, obj) in collection.as_ref() { @@ -2162,9 +2162,9 @@ mod tests { t: &mut MTree, map: &HashMap, ) -> Result<(), Error> { - let (s, mut tx) = new_operation(&ds, TreeStoreType::Read).await; + let (s, mut tx) = new_operation(ds, TreeStoreType::Read).await; let mut s = s.lock().await; - for (_, obj) in map { + for obj in map.values() { let res = t.knn_search(&mut tx, &mut s, obj, map.len()).await?; assert_eq!( map.len(), @@ -2234,7 +2234,7 @@ mod tests { impl AsRef> for TestCollection { fn as_ref(&self) -> &Vec<(DocId, SharedVector)> { match self { - TestCollection::Unique(c) | TestCollection::NonUnique(c) => &c, + TestCollection::Unique(c) | TestCollection::NonUnique(c) => c, } } } diff --git a/lib/src/kvs/tests/ndlq.rs b/lib/src/kvs/tests/ndlq.rs index 0920f569..515c13ab 100644 --- a/lib/src/kvs/tests/ndlq.rs +++ b/lib/src/kvs/tests/ndlq.rs @@ -14,7 +14,7 @@ async fn write_scan_ndlq() { let tb = "table"; let lq = sql::Uuid::from(uuid::Uuid::parse_str("4c3dca4b-ec08-4e3e-b23a-6b03b5cdc3fc").unwrap()); - tx.putc_ndlq(nd, lq.clone().0, ns, db, tb, None).await.unwrap(); + tx.putc_ndlq(nd, lq.0, ns, db, tb, None).await.unwrap(); tx.commit().await.unwrap(); // Verify scan diff --git a/lib/src/kvs/tests/nq.rs b/lib/src/kvs/tests/nq.rs index 99acff08..38b32f9b 100644 --- a/lib/src/kvs/tests/nq.rs +++ b/lib/src/kvs/tests/nq.rs @@ -19,7 +19,7 @@ async fn archive_lv_for_node_archives() { tx.putc(key, table, None).await.unwrap(); let mut stm = LiveStatement::from_source_parts(Fields::all(), Table(table.into()), None, None); - stm.id = lv_id.clone(); + stm.id = lv_id; tx.putc_tblq(namespace, database, table, stm, None).await.unwrap(); let this_node_id = crate::sql::uuid::Uuid::from(Uuid::from_bytes([ @@ -33,7 +33,7 @@ async fn archive_lv_for_node_archives() { let mut tx = test.db.transaction(Write, Optimistic).await.unwrap(); let results = test .db - .archive_lv_for_node(&mut tx, &sql::uuid::Uuid(node_id), this_node_id.clone()) + .archive_lv_for_node(&mut tx, &sql::uuid::Uuid(node_id), this_node_id) .await .unwrap(); assert_eq!(results.len(), 1); diff --git a/lib/src/kvs/tests/tblq.rs b/lib/src/kvs/tests/tblq.rs index 2a053fa4..f1dcc656 100644 --- a/lib/src/kvs/tests/tblq.rs +++ b/lib/src/kvs/tests/tblq.rs @@ -20,7 +20,7 @@ async fn write_scan_tblq() { let tb = "table"; let live_id = sql::Uuid::from(live_id); let live_stm = LiveStatement { - id: live_id.clone(), + id: live_id, node: sql::Uuid::from(node_id), expr: Default::default(), what: Default::default(),