fix(tests): enhance Windows compatibility and test stability

- Normalize file paths to use forward slashes in Git pattern matching for better compatibility across platforms.
- Introduce a random suffix to temporary directory names in tests on Windows to avoid file lock contention during parallel execution.
- Add a delay after shutdown in tests to ensure SQLite file locks are released properly on Windows.

These changes aim to improve the reliability and consistency of tests in a Windows environment.
This commit is contained in:
Jamie Pine
2025-12-31 12:45:22 -08:00
parent 9f404225a6
commit 32e7fe9ca1
3 changed files with 34 additions and 3 deletions

View File

@@ -146,9 +146,12 @@ fn accept_by_git_pattern(
Ok(p) => p,
Err(_) => return true,
};
let Some(src) = relative.to_str().map(|s| s.as_bytes().into()) else {
let Some(path_str) = relative.to_str() else {
return false;
};
// Gitignore patterns expect forward slashes, even on Windows
let normalized_path = path_str.replace('\\', "/");
let src = normalized_path.as_bytes().into();
search
.pattern_matching_relative_path(src, Some(source.is_dir()), Case::Fold)
.map_or(true, |rule| rule.pattern.is_negative())

View File

@@ -275,6 +275,13 @@ impl IndexingHarness {
.await
.map_err(|e| anyhow::anyhow!("Failed to shutdown core: {}", e))?;
// On Windows, SQLite file locks can persist after shutdown even after WAL checkpoint
// This is due to the connection pool in SeaORM potentially holding onto connections
// Give the OS sufficient time to release all locks before TestDataDir cleanup
// Tests running in sequence need time for previous test's locks to fully release
#[cfg(windows)]
tokio::time::sleep(Duration::from_secs(2)).await;
// TestDataDir handles cleanup automatically on drop
Ok(())
}

View File

@@ -57,10 +57,31 @@ impl TestDataDir {
}
};
// On Windows, add a random suffix to avoid file lock contention in parallel tests
let dir_name = if use_home_for_watcher {
format!(".spacedrive_test_{}", test_name)
#[cfg(windows)]
{
use std::sync::atomic::{AtomicU64, Ordering};
static COUNTER: AtomicU64 = AtomicU64::new(0);
let id = COUNTER.fetch_add(1, Ordering::Relaxed);
format!(".spacedrive_test_{}_{}", test_name, id)
}
#[cfg(not(windows))]
{
format!(".spacedrive_test_{}", test_name)
}
} else {
format!("spacedrive-test-{}", test_name)
#[cfg(windows)]
{
use std::sync::atomic::{AtomicU64, Ordering};
static COUNTER: AtomicU64 = AtomicU64::new(0);
let id = COUNTER.fetch_add(1, Ordering::Relaxed);
format!("spacedrive-test-{}-{}", test_name, id)
}
#[cfg(not(windows))]
{
format!("spacedrive-test-{}", test_name)
}
};
let temp_path = PathBuf::from(temp_base).join(dir_name);