mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-19 13:55:40 -04:00
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:
@@ -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())
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user