From e6e4aef45bce736635c1cc803c2bf61cfbc1e691 Mon Sep 17 00:00:00 2001 From: houseme Date: Fri, 10 Jul 2026 10:08:56 +0800 Subject: [PATCH] test(ecstore): cover the io_uring per-disk probe cache hit (backlog#1101) (#4641) test(ecstore): cover the io_uring per-disk probe cache hit (rustfs/backlog#1101) Follow-up to #4635. The per-disk negative probe cache was implemented but had no dedicated test. Add uring_probe_cache_skips_known_unsupported_disk: a root recorded in URING_UNSUPPORTED_DISKS makes try_new return None without a fresh probe. Completes the #1101 acceptance ("cache hit does not re-probe"). Co-authored-by: heihutu --- crates/ecstore/src/disk/local.rs | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/crates/ecstore/src/disk/local.rs b/crates/ecstore/src/disk/local.rs index ee8a2eeac..a000dbabe 100644 --- a/crates/ecstore/src/disk/local.rs +++ b/crates/ecstore/src/disk/local.rs @@ -11354,6 +11354,41 @@ mod test { assert!(!is_io_uring_unsupported(&Error::other("driver gone"))); } + /// Per-disk probe cache (backlog#1101): a disk already recorded as + /// unsupported is skipped by `try_new` without a fresh probe. + #[cfg(target_os = "linux")] + #[test] + fn uring_probe_cache_skips_known_unsupported_disk() { + use tempfile::tempdir; + + // Precondition: io_uring must be usable on this host. Otherwise a `None` + // result below is ambiguous — it could be a probe failure rather than + // the cache fast-path — so the test would pass vacuously in a restricted + // CI environment. Probe an uncached root; skip if io_uring is + // unavailable. (The returned backend, if any, is dropped immediately, + // shutting its driver down.) + let probe_dir = tempdir().expect("tempdir"); + if UringBackend::try_new(probe_dir.path().to_path_buf()).is_none() { + return; + } + + // Now a `None` for a cached-unsupported root can ONLY be the cache + // fast-path (io_uring works here, so a fresh probe would have succeeded). + let cached = std::path::PathBuf::from("/nonexistent/uring-probe-cache-test-root"); + URING_UNSUPPORTED_DISKS + .lock() + .expect("uring probe cache mutex poisoned") + .insert(cached.clone()); + let skipped = UringBackend::try_new(cached.clone()).is_none(); + // Clean up the process-wide cache entry so no shared state leaks to + // other tests. + URING_UNSUPPORTED_DISKS + .lock() + .expect("uring probe cache mutex poisoned") + .remove(&cached); + assert!(skipped, "a cached-unsupported disk must skip the probe and return None"); + } + /// Once io_uring is latched off (backlog#1101), reads still return correct /// bytes via StdBackend. Lay out the disk with LocalDisk, then read the same /// root through a UringBackend with the latch tripped.