summaryrefslogtreecommitdiff
path: root/morphology-img/tests
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-17 08:55:46 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-17 08:55:46 +0100
commit7087c4f7da3749f12a2daa1e1de1c7f947e91638 (patch)
tree99011c9b8a936076396733e5145ec241f53def7d /morphology-img/tests
parente37f7ba671f3e80396e7a4ac3a461365bd0ca78a (diff)
feature: ly parallel processing
Diffstat (limited to 'morphology-img/tests')
-rw-r--r--morphology-img/tests/config.rs56
-rw-r--r--morphology-img/tests/integration.rs193
2 files changed, 249 insertions, 0 deletions
diff --git a/morphology-img/tests/config.rs b/morphology-img/tests/config.rs
index 6302cb0..7cc71cb 100644
--- a/morphology-img/tests/config.rs
+++ b/morphology-img/tests/config.rs
@@ -240,3 +240,59 @@ fn test_max_batch_size_field_is_public() {
let _batch_size = config.max_batch_size;
assert_eq!(_batch_size, Some(15));
}
+
+#[test]
+fn test_default_parallel_is_false() {
+ let config = RenderConfig::default();
+ assert!(!config.parallel);
+}
+
+#[test]
+fn test_builder_parallel_true() {
+ let config = RenderConfig::new("output")
+ .parallel(true);
+
+ assert!(config.parallel);
+ assert_eq!(config.output_dir, PathBuf::from("output"));
+}
+
+#[test]
+fn test_builder_parallel_false() {
+ let config = RenderConfig::new("output")
+ .parallel(false);
+
+ assert!(!config.parallel);
+}
+
+#[test]
+fn test_builder_parallel_overwrites() {
+ let config = RenderConfig::new("output")
+ .parallel(true)
+ .parallel(false); // Override previous value
+
+ assert!(!config.parallel);
+}
+
+#[test]
+fn test_builder_with_all_options_including_parallel() {
+ let config = RenderConfig::new("my-output")
+ .keep_temp_files(true)
+ .lilypond_binary("/usr/bin/lilypond")
+ .max_batch_size(25)
+ .parallel(true);
+
+ assert_eq!(config.output_dir, PathBuf::from("my-output"));
+ assert!(config.keep_temp_files);
+ assert_eq!(config.lilypond_binary, PathBuf::from("/usr/bin/lilypond"));
+ assert_eq!(config.max_batch_size, Some(25));
+ assert!(config.parallel);
+}
+
+#[test]
+fn test_parallel_field_is_public() {
+ let config = RenderConfig::new("output").parallel(true);
+
+ // Should be able to access field directly
+ let _parallel = config.parallel;
+ assert!(_parallel);
+}
diff --git a/morphology-img/tests/integration.rs b/morphology-img/tests/integration.rs
index c8b60fc..423d668 100644
--- a/morphology-img/tests/integration.rs
+++ b/morphology-img/tests/integration.rs
@@ -720,3 +720,196 @@ fn test_batch_size_one() {
assert!(path.exists());
}
}
+
+// ============================================================================
+// Parallel Processing Tests
+// ============================================================================
+
+#[test]
+#[ignore]
+fn test_parallel_rendering_basic() {
+ // Test that parallel rendering works correctly
+ let sequences: Vec<Sequence> = (0..10)
+ .map(|i| {
+ Sequence::new(vec![Value::new(i, 0)])
+ })
+ .collect();
+
+ let output_dir = TempDir::new().unwrap();
+ let config = RenderConfig::new(output_dir.path())
+ .parallel(true);
+
+ let svg_paths = render_sequences(&sequences, &config).unwrap();
+
+ assert_eq!(svg_paths.len(), 10);
+ for path in &svg_paths {
+ assert!(path.exists(), "SVG file should exist: {}", path.display());
+ }
+}
+
+#[test]
+#[ignore]
+fn test_parallel_vs_sequential_same_results() {
+ // Verify that parallel and sequential produce the same results
+ let sequences: Vec<Sequence> = (0..5)
+ .map(|i| {
+ Sequence::new(vec![Value::new(i, 0), Value::new(i, 1)])
+ })
+ .collect();
+
+ // Sequential rendering
+ let output_dir_seq = TempDir::new().unwrap();
+ let config_seq = RenderConfig::new(output_dir_seq.path())
+ .parallel(false);
+
+ let svg_paths_seq = render_sequences(&sequences, &config_seq).unwrap();
+
+ // Parallel rendering
+ let output_dir_par = TempDir::new().unwrap();
+ let config_par = RenderConfig::new(output_dir_par.path())
+ .parallel(true);
+
+ let svg_paths_par = render_sequences(&sequences, &config_par).unwrap();
+
+ // Both should produce same number of files
+ assert_eq!(svg_paths_seq.len(), svg_paths_par.len());
+
+ // Both should have files with same names
+ for (seq_path, par_path) in svg_paths_seq.iter().zip(svg_paths_par.iter()) {
+ assert_eq!(
+ seq_path.file_name(),
+ par_path.file_name(),
+ "Sequential and parallel should produce same filenames"
+ );
+ assert!(seq_path.exists());
+ assert!(par_path.exists());
+ }
+}
+
+#[test]
+#[ignore]
+fn test_parallel_with_progress_callback() {
+ // Test that progress callbacks work with parallel rendering
+ let sequences: Vec<Sequence> = (0..8)
+ .map(|i| {
+ Sequence::new(vec![Value::new(i, 0)])
+ })
+ .collect();
+
+ let progress_calls = Arc::new(Mutex::new(Vec::new()));
+ let progress_calls_clone = progress_calls.clone();
+
+ let callback: ProgressCallback = Arc::new(move |current, total| {
+ progress_calls_clone.lock().unwrap().push((current, total));
+ });
+
+ let output_dir = TempDir::new().unwrap();
+ let config = RenderConfig::new(output_dir.path())
+ .parallel(true)
+ .progress_callback(callback);
+
+ let svg_paths = render_sequences(&sequences, &config).unwrap();
+
+ assert_eq!(svg_paths.len(), 8);
+
+ // Progress callback should have been called 8 times
+ let calls = progress_calls.lock().unwrap();
+ assert_eq!(calls.len(), 8, "Progress callback should be called for each file");
+
+ // All calls should have total=8
+ for (_current, total) in calls.iter() {
+ assert_eq!(*total, 8, "Total should always be 8");
+ }
+}
+
+#[test]
+#[ignore]
+fn test_parallel_default_is_false() {
+ let config = RenderConfig::default();
+ assert!(!config.parallel, "Parallel should default to false");
+
+ let config2 = RenderConfig::new("output");
+ assert!(!config2.parallel, "Parallel should default to false");
+}
+
+#[test]
+#[ignore]
+fn test_parallel_with_batch_chunking() {
+ // Test parallel rendering combined with batch chunking
+ let sequences: Vec<Sequence> = (0..15)
+ .map(|i| {
+ Sequence::new(vec![Value::new(i, 0)])
+ })
+ .collect();
+
+ let output_dir = TempDir::new().unwrap();
+ let config = RenderConfig::new(output_dir.path())
+ .parallel(true)
+ .max_batch_size(5);
+
+ let svg_paths = render_sequences(&sequences, &config).unwrap();
+
+ // All 15 SVGs should be created
+ assert_eq!(svg_paths.len(), 15);
+
+ // Verify files are in order (sequence-00.svg through sequence-14.svg)
+ for (i, path) in svg_paths.iter().enumerate() {
+ let expected_filename = format!("sequence-{:02}.svg", i);
+ assert_eq!(
+ path.file_name().unwrap().to_str().unwrap(),
+ expected_filename,
+ "Files should be in correct order"
+ );
+ assert!(path.exists());
+ }
+}
+
+#[test]
+#[ignore]
+fn test_benchmark_parallel_vs_sequential() {
+ use std::time::Instant;
+
+ // Create many sequences for meaningful benchmark
+ let sequences: Vec<Sequence> = (0..20)
+ .map(|i| {
+ Sequence::new(vec![Value::new(i, 0)])
+ })
+ .collect();
+
+ // Sequential rendering
+ let output_dir_seq = TempDir::new().unwrap();
+ let config_seq = RenderConfig::new(output_dir_seq.path())
+ .parallel(false);
+
+ let start = Instant::now();
+ let svg_paths_seq = render_sequences(&sequences, &config_seq).unwrap();
+ let sequential_time = start.elapsed();
+
+ assert_eq!(svg_paths_seq.len(), 20);
+
+ // Parallel rendering
+ let output_dir_par = TempDir::new().unwrap();
+ let config_par = RenderConfig::new(output_dir_par.path())
+ .parallel(true);
+
+ let start = Instant::now();
+ let svg_paths_par = render_sequences(&sequences, &config_par).unwrap();
+ let parallel_time = start.elapsed();
+
+ assert_eq!(svg_paths_par.len(), 20);
+
+ // Print timing results
+ println!("\n=== Parallel vs Sequential Benchmark (20 sequences) ===");
+ println!("Sequential time: {:?}", sequential_time);
+ println!("Parallel time: {:?}", parallel_time);
+
+ if parallel_time < sequential_time {
+ let speedup = sequential_time.as_secs_f64() / parallel_time.as_secs_f64();
+ println!("Speedup: {:.2}x faster", speedup);
+ } else {
+ println!("Note: Parallel was slower (overhead or system constraints)");
+ }
+
+ // No strict assertion on speed - depends on system
+ // Just verify both completed successfully
+}