Skip to content

Commit b6bdf4a

Browse files
OneZero-Yrootfs
authored andcommitted
fix:Improve rust unit test and optimize concurrent tests with rayon (#471)
- Add 6 new unit test files - Replace std::thread::spawn with rayon::par_iter Signed-off-by: OneZero-Y <[email protected]> Signed-off-by: Huamin Chen <[email protected]>
1 parent 87c1030 commit b6bdf4a

File tree

10 files changed

+2508
-11
lines changed

10 files changed

+2508
-11
lines changed

candle-binding/src/classifiers/lora/parallel_engine_test.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tests for Parallel LoRA Engine with performance benchmarks
22
33
use crate::test_fixtures::fixtures::*;
4+
use rayon::prelude::*;
45
use rstest::*;
56
use serial_test::serial;
67
use std::sync::Arc;
@@ -207,19 +208,14 @@ fn test_performance_concurrent_requests(
207208
println!("\n🔢 Testing with {} concurrent requests", num_threads);
208209

209210
let start = Instant::now();
210-
let handles: Vec<_> = (0..*num_threads)
211-
.map(|_| {
212-
let classifier = Arc::clone(classifier);
213-
std::thread::spawn(move || classifier.classify_intent(test_text))
214-
})
211+
212+
// Use rayon for parallel execution - simpler and more efficient
213+
let results: Vec<_> = (0..*num_threads)
214+
.into_par_iter()
215+
.map(|_| classifier.classify_intent(test_text))
215216
.collect();
216217

217-
let mut success_count = 0;
218-
for handle in handles {
219-
if handle.join().is_ok() {
220-
success_count += 1;
221-
}
222-
}
218+
let success_count = results.iter().filter(|r| r.is_ok()).count();
223219

224220
let duration = start.elapsed();
225221
println!(

candle-binding/src/core/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ pub use tokenization::{
3434
#[cfg(test)]
3535
pub mod config_loader_test;
3636
#[cfg(test)]
37+
pub mod similarity_test;
38+
#[cfg(test)]
39+
pub mod tokenization_test;
40+
#[cfg(test)]
3741
pub mod unified_error_test;

0 commit comments

Comments
 (0)