From ef1475f864777f87a1d649c8f0ea5e32ff348af3 Mon Sep 17 00:00:00 2001 From: Bet4 <0xbet4@gmail.com> Date: Sat, 17 Oct 2026 00:21:53 +0800 Subject: [PATCH] test: sync noise file so allocation units commit on CoW filesystems --- crates/disktree-core/src/scan.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/disktree-core/src/scan.rs b/crates/disktree-core/src/scan.rs index 693253a7..f7ffaeb5 100644 --- a/crates/disktree-core/src/scan.rs +++ b/crates/disktree-core/src/scan.rs @@ -1647,7 +1647,14 @@ mod tests { state.to_le_bytes()[0] }) .collect(); - fs::write(temp.path().join("data.bin"), noise).expect("write"); + // Flush and sync before scanning: on CoW filesystems with delayed + // allocation (such as OpenZFS), asynchronous writes remain buffered + // in transaction groups and report st_blocks = 1 until synced. + let mut file = + fs::File::create(temp.path().join("data.bin")).expect("create"); + std::io::Write::write_all(&mut file, &noise).expect("write"); + file.sync_all().expect("sync"); + drop(file); let tree = scan_dir(temp.path(), &ScanOptions::default()); assert!(tree.bytes >= 100_000, "{}", tree.bytes); assert_eq!(tree.bytes % 512, 0, "{}", tree.bytes);