From d3bb8beb1706fdcf90db21c97fe02adf2e3760c6 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Tue, 14 Oct 2025 13:45:37 -0300 Subject: [PATCH] Run SQLite integrity check after stress test run --- Cargo.lock | 1 + stress/Cargo.toml | 1 + stress/main.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index dd15bab8d..58da1ef9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4559,6 +4559,7 @@ dependencies = [ "antithesis_sdk", "clap", "hex", + "rusqlite", "tempfile", "tokio", "tracing", diff --git a/stress/Cargo.toml b/stress/Cargo.toml index 2e51f003c..077f5f003 100644 --- a/stress/Cargo.toml +++ b/stress/Cargo.toml @@ -30,3 +30,4 @@ tracing = { workspace = true } tracing-appender = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } turso = { workspace = true } +rusqlite = { workspace = true } diff --git a/stress/main.rs b/stress/main.rs index f2ec5a179..313098b3b 100644 --- a/stress/main.rs +++ b/stress/main.rs @@ -450,6 +450,31 @@ pub fn init_tracing() -> Result { Ok(guard) } +fn integrity_check( + db_path: &std::path::Path, +) -> Result<(), Box> { + assert!(db_path.exists()); + let conn = rusqlite::Connection::open(db_path)?; + let mut stmt = conn.prepare("SELECT * FROM pragma_integrity_check;")?; + let mut rows = stmt.query(())?; + let mut result: Vec = Vec::new(); + + while let Some(row) = rows.next()? { + result.push(row.get(0)?); + } + if result.is_empty() { + return Err( + "simulation failed: integrity_check should return `ok` or a list of problems".into(), + ); + } + if !result[0].eq_ignore_ascii_case("ok") { + // Build a list of problems + result.iter_mut().for_each(|row| *row = format!("- {row}")); + return Err(format!("simulation failed: {}", result.join("\n")).into()); + } + Ok(()) +} + #[tokio::main] async fn main() -> Result<(), Box> { let _g = init_tracing()?; @@ -614,5 +639,10 @@ async fn main() -> Result<(), Box> { } println!("Done. SQL statements written to {}", opts.log_file); println!("Database file: {db_file}"); + + println!("Running SQLite Integrity check"); + + integrity_check(std::path::Path::new(&db_file))?; + Ok(()) }