refactor: improve test structure and reliability

This commit is contained in:
Andrew Phillips
2025-05-12 13:07:33 -03:00
committed by Andrew Phillips (aider)
parent eaf341cdfb
commit d9072d22d5
5 changed files with 395 additions and 263 deletions

View File

@@ -1,7 +1,7 @@
use crate::compression::CompressionType;
use libc::c_int;
use std::path::PathBuf;
use std::str::FromStr;
use libc::c_int;
use anyhow::{anyhow, Result};
use clap::Command;
@@ -150,26 +150,16 @@ pub fn mode_diff(
) -> std::thread::JoinHandle<()> {
let pipe_writer_raw = unsafe { std::fs::File::from_raw_fd(fd_write) };
std::thread::spawn(move || {
write_item_to_pipe(
item_path,
compression_type,
pipe_writer_raw,
);
write_item_to_pipe(item_path, compression_type, pipe_writer_raw);
})
}
// Spawn writer threads for both items
let writer_thread_a = spawn_writer_thread(
item_path_a.clone(),
compression_type_a.clone(),
fd_a_write,
);
let writer_thread_a =
spawn_writer_thread(item_path_a.clone(), compression_type_a.clone(), fd_a_write);
let writer_thread_b = spawn_writer_thread(
item_path_b.clone(),
compression_type_b.clone(),
fd_b_write,
);
let writer_thread_b =
spawn_writer_thread(item_path_b.clone(), compression_type_b.clone(), fd_b_write);
// Thread to read diff's standard output
let stdout_reader_thread = std::thread::spawn(move || {
@@ -232,19 +222,19 @@ pub fn mode_diff(
let stdout_capture_result = stdout_reader_thread
.join()
.unwrap_or_else(|panic_payload| {
Err(anyhow!(
"Stdout reader thread panicked: {:?}",
panic_payload
))
})?;
Err(anyhow!(
"Stdout reader thread panicked: {:?}",
panic_payload
))
})?;
let stderr_capture_result = stderr_reader_thread
.join()
.unwrap_or_else(|panic_payload| {
Err(anyhow!(
"Stderr reader thread panicked: {:?}",
panic_payload
))
})?;
Err(anyhow!(
"Stderr reader thread panicked: {:?}",
panic_payload
))
})?;
// Handle diff's exit status and output
match diff_status.code() {