use std::fs::{self, File};
use std::io::Write;
use tempfile::TempDir;
fn create_directory_with_files(dir: &std::path::Path, count: usize) -> std::io::Result<()> {
for i in 0..count {
let file_path = dir.join(format!("file{:06}.txt", i));
let mut file = File::create(file_path)?;
write!(file, "File {} content: ", i)?;
file.write_all(&vec![b'x'; 1000])?;
}
Ok(())
}
#[test]
#[ignore] fn test_sync_1000_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 1,000 test files...");
create_directory_with_files(source_dir.path(), 1_000).unwrap();
let start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.output()
.expect("Failed to execute sy");
let elapsed = start.elapsed();
assert!(output.status.success(), "Sync failed: {:?}", String::from_utf8_lossy(&output.stderr));
let dest_count = fs::read_dir(dest_dir.path()).unwrap().count();
assert_eq!(dest_count, 1_000, "Not all files were copied");
println!("✅ 1,000 files synced in {:?}", elapsed);
}
#[test]
#[ignore] fn test_sync_10k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 10,000 test files...");
create_directory_with_files(source_dir.path(), 10_000).unwrap();
let start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.arg("-v")
.output()
.expect("Failed to execute sy");
let elapsed = start.elapsed();
assert!(output.status.success(), "Sync failed: {:?}", String::from_utf8_lossy(&output.stderr));
let dest_count = fs::read_dir(dest_dir.path()).unwrap().count();
assert_eq!(dest_count, 10_000, "Not all files were copied");
let stderr = String::from_utf8_lossy(&output.stderr);
let has_bloom = stderr.contains("Bloom") || stderr.contains("bloom");
println!("Bloom filter used: {}", has_bloom);
println!("✅ 10,000 files synced in {:?}", elapsed);
}
#[test]
#[ignore] fn test_sync_100k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 100,000 test files (this may take a few minutes)...");
let create_start = std::time::Instant::now();
create_directory_with_files(source_dir.path(), 100_000).unwrap();
let create_elapsed = create_start.elapsed();
println!("Created 100,000 files in {:?}", create_elapsed);
println!("Syncing 100,000 files...");
let sync_start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.arg("-v")
.output()
.expect("Failed to execute sy");
let sync_elapsed = sync_start.elapsed();
assert!(output.status.success(), "Sync failed: {:?}", String::from_utf8_lossy(&output.stderr));
println!("Verifying file count...");
let dest_count = fs::read_dir(dest_dir.path()).unwrap().count();
assert_eq!(dest_count, 100_000, "Not all files were copied");
println!("✅ 100,000 files synced in {:?}", sync_elapsed);
}
#[test]
#[ignore] fn test_idempotent_sync_10k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 10,000 test files...");
create_directory_with_files(source_dir.path(), 10_000).unwrap();
println!("First sync...");
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.output()
.expect("Failed to execute sy");
assert!(output.status.success(), "First sync failed");
println!("Second sync (idempotent)...");
let start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.output()
.expect("Failed to execute sy");
let elapsed = start.elapsed();
assert!(output.status.success(), "Second sync failed");
assert!(elapsed.as_secs() < 5, "Idempotent sync too slow: {:?}", elapsed);
println!("✅ Idempotent sync of 10,000 files: {:?}", elapsed);
}
#[test]
#[ignore] fn test_deletion_planning_10k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 10,000 source files...");
create_directory_with_files(source_dir.path(), 10_000).unwrap();
println!("Creating 100 extra dest files to delete...");
for i in 0..100 {
let file_path = dest_dir.path().join(format!("delete{:06}.txt", i));
File::create(file_path).unwrap();
}
let start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.arg("--delete")
.arg("--force-delete")
.output()
.expect("Failed to execute sy");
let elapsed = start.elapsed();
assert!(output.status.success(), "Sync failed: {:?}", String::from_utf8_lossy(&output.stderr));
let dest_count = fs::read_dir(dest_dir.path()).unwrap().count();
assert_eq!(dest_count, 10_000, "Deletion planning failed");
println!("✅ Deletion planning with 10,000 files: {:?}", elapsed);
}
#[test]
#[ignore] fn test_nested_directories_10k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating nested directory structure (100 dirs × 100 files)...");
for dir_idx in 0..100 {
let subdir = source_dir.path().join(format!("dir{:03}", dir_idx));
fs::create_dir(&subdir).unwrap();
for file_idx in 0..100 {
let file_path = subdir.join(format!("file{:03}.txt", file_idx));
let mut file = File::create(file_path).unwrap();
write!(file, "Content for dir{}/file{}", dir_idx, file_idx).unwrap();
}
}
let start = std::time::Instant::now();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.output()
.expect("Failed to execute sy");
let elapsed = start.elapsed();
assert!(output.status.success(), "Sync failed: {:?}", String::from_utf8_lossy(&output.stderr));
let dir_count = fs::read_dir(dest_dir.path()).unwrap().count();
assert_eq!(dir_count, 100, "Not all directories were copied");
let sample_dir = dest_dir.path().join("dir050");
let file_count = fs::read_dir(&sample_dir).unwrap().count();
assert_eq!(file_count, 100, "Not all files in subdirectory were copied");
println!("✅ Nested 10,000 files synced in {:?}", elapsed);
}
#[test]
#[ignore] fn test_progress_accuracy_10k_files() {
let source_dir = TempDir::new().unwrap();
let dest_dir = TempDir::new().unwrap();
println!("Creating 10,000 test files...");
create_directory_with_files(source_dir.path(), 10_000).unwrap();
let output = std::process::Command::new(env!("CARGO_BIN_EXE_sy"))
.arg(source_dir.path())
.arg(dest_dir.path())
.arg("--json")
.output()
.expect("Failed to execute sy");
assert!(output.status.success(), "Sync failed");
let stdout = String::from_utf8_lossy(&output.stdout);
let mut file_count = 0;
for line in stdout.lines() {
if let Ok(event) = serde_json::from_str::<serde_json::Value>(line) {
let event_type = event["type"].as_str().unwrap_or("");
if event_type == "create" || event_type == "update" {
file_count += 1;
}
}
}
assert!(file_count >= 10_000, "Progress tracking missed files: expected 10000, got {}", file_count);
println!("✅ Progress tracking accurate for 10,000 files");
}