From 06b12557334c545e2b664947657afb887d832ace Mon Sep 17 00:00:00 2001 From: Johanna Larsson Date: Mon, 21 Sep 2026 21:19:29 +0100 Subject: [PATCH] Skip fsync when running tests Flushing to disk all the time ensures no partial states when writing to disk during awkwardnesses like crashes in prod risking real user data. That's good! We're also doing it while running tests. Less good! Well, at least not important! Comparing a clean test run (`just test --no-fail-fast`) and a run on this branch, on my MacOS M4 Pro, I get: `**Summary** [ 517.723s] **1424** tests run: **1405** **passed** (**7** **slow**), **19** **failed**, **15** **skipped**` before and `**Summary** [ 326.369s] **1424** tests run: **1405** **passed**, **19** **failed**, **15** **skipped**` after. The reason I run `--no-fail-fast` is that a bunch of tests always fail and time out and stuff --- crates/tranquil-store/Cargo.toml | 1 + crates/tranquil-store/src/io.rs | 12 ++++++++++++ crates/tranquil-store/src/metastore/mod.rs | 11 ++++++++--- justfile | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/tranquil-store/Cargo.toml b/crates/tranquil-store/Cargo.toml index e73e495..8c73dce 100644 --- a/crates/tranquil-store/Cargo.toml +++ b/crates/tranquil-store/Cargo.toml @@ -46,6 +46,7 @@ test-harness = ["dep:tempfile"] jemalloc = ["dep:tikv-jemallocator"] gauntlet-cli = ["test-harness", "dep:clap", "dep:toml", "dep:tracing-subscriber", "jemalloc"] gauntlet-jemalloc-prof = [] +skip-fsync = [] [[bin]] name = "tranquil-gauntlet" diff --git a/crates/tranquil-store/src/io.rs b/crates/tranquil-store/src/io.rs index a9a57e6..eceed66 100644 --- a/crates/tranquil-store/src/io.rs +++ b/crates/tranquil-store/src/io.rs @@ -267,10 +267,16 @@ impl StorageIO for RealIO { self.lookup(id)?.write_at(buf, offset) } + #[cfg(not(feature = "skip-fsync"))] fn sync(&self, id: FileId) -> io::Result<()> { self.lookup(id)?.sync_data() } + #[cfg(feature = "skip-fsync")] + fn sync(&self, id: FileId) -> io::Result<()> { + self.lookup(id).map(|_| ()) + } + fn file_size(&self, id: FileId) -> io::Result { self.lookup(id)?.metadata().map(|m| m.len()) } @@ -291,10 +297,16 @@ impl StorageIO for RealIO { fs::create_dir_all(path) } + #[cfg(not(feature = "skip-fsync"))] fn sync_dir(&self, path: &Path) -> io::Result<()> { fs::File::open(path)?.sync_all() } + #[cfg(feature = "skip-fsync")] + fn sync_dir(&self, path: &Path) -> io::Result<()> { + fs::File::open(path).map(|_| ()) + } + fn list_dir(&self, path: &Path) -> io::Result> { fs::read_dir(path)? .map(|entry| entry.map(|e| e.path())) diff --git a/crates/tranquil-store/src/metastore/mod.rs b/crates/tranquil-store/src/metastore/mod.rs index 4f22bfb..fc97b95 100644 --- a/crates/tranquil-store/src/metastore/mod.rs +++ b/crates/tranquil-store/src/metastore/mod.rs @@ -42,6 +42,11 @@ use self::user_hash::UserHashMap; const CURRENT_FORMAT_VERSION: u64 = 3; +#[cfg(feature = "skip-fsync")] +const METASTORE_PERSIST_MODE: fjall::PersistMode = fjall::PersistMode::Buffer; +#[cfg(not(feature = "skip-fsync"))] +const METASTORE_PERSIST_MODE: fjall::PersistMode = fjall::PersistMode::SyncData; + #[derive(Debug, Clone)] pub struct MetastoreConfig { pub cache_size_bytes: u64, @@ -243,14 +248,14 @@ impl Metastore { repo_data.remove(records::record_by_cid_built_key().as_slice())?; Self::migrate_blob_ownership(db, repo_data)?; repo_data.insert(version_key, version_bytes)?; - db.persist(fjall::PersistMode::SyncData)?; + db.persist(METASTORE_PERSIST_MODE)?; Ok(()) } } } None => { repo_data.insert(version_key, version_bytes)?; - db.persist(fjall::PersistMode::SyncData)?; + db.persist(METASTORE_PERSIST_MODE)?; Ok(()) } } @@ -427,7 +432,7 @@ impl Metastore { pub fn persist(&self) -> Result<(), MetastoreError> { self.db - .persist(fjall::PersistMode::SyncData) + .persist(METASTORE_PERSIST_MODE) .map_err(MetastoreError::Fjall) } diff --git a/justfile b/justfile index be34371..2faa600 100644 --- a/justfile +++ b/justfile @@ -98,7 +98,7 @@ test-store-asan: test-unit: SQLX_OFFLINE=true cargo test --test dpop_unit --test validation_edge_cases --test scope_edge_cases -store_test := "SQLX_OFFLINE=true TRANQUIL_TEST_BACKEND=store TRANQUIL_PDS_ALLOW_INSECURE_SECRETS=1 DISABLE_RATE_LIMITING=1 TRANQUIL_LEXICON_OFFLINE=1 SKIP_IMPORT_VERIFICATION=true cargo nextest run -E 'not package(tranquil-store) and not binary(store_parity)'" +store_test := "SQLX_OFFLINE=true TRANQUIL_TEST_BACKEND=store TRANQUIL_PDS_ALLOW_INSECURE_SECRETS=1 DISABLE_RATE_LIMITING=1 TRANQUIL_LEXICON_OFFLINE=1 SKIP_IMPORT_VERIFICATION=true cargo nextest run --features tranquil-store/skip-fsync -E 'not package(tranquil-store) and not binary(store_parity)'" test-auth: {{store_test}} --test oauth --test oauth_lifecycle --test oauth_scopes --test oauth_security --test jwt_security --test session_management --test change_password --test password_reset