fix(object-store): make removed-entry lister test portable (#8752)

(cherry picked from commit 4e43c279ff)
Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
discord9
2026-08-21 17:58:22 +08:00
parent 6f150e01cd
commit cb52adcbf7
+16 -1
View File
@@ -622,6 +622,14 @@ mod tests {
assert!(operator.list("file/").await.unwrap().is_empty());
}
// On Windows, `std::fs::DirEntry` is a snapshot taken by
// `FindFirstFileW`: `file_type()` and `metadata()` keep returning the
// cached data even after the file is removed, so `read_list_entry`
// may return `Some` with the stale entry. On platforms where metadata
// is fetched from the live filesystem (e.g. Unix `lstat` returns
// `ENOENT` after removal), `read_list_entry` returns `None` instead.
// The strong assertion is Unix-specific; the portable part still
// verifies the call succeeds and yields the expected path.
#[test]
fn test_lister_skips_entry_removed_during_iteration() {
let temp_dir = create_temp_dir("secure_fs_lister_removed_entry");
@@ -632,7 +640,14 @@ mod tests {
let entry = read_dir.next().unwrap().unwrap();
std::fs::remove_file(path).unwrap();
assert!(read_list_entry(entry, "").unwrap().is_none());
let result = read_list_entry(entry, "").unwrap();
if let Some(entry) = &result {
assert_eq!("removed", entry.path());
}
#[cfg(not(windows))]
assert!(result.is_none());
}
#[tokio::test]