Run SQLite integrity check after stress test run

This commit is contained in:
pedrocarlo
2025-10-14 13:45:37 -03:00
parent 7cf51e74ca
commit d3bb8beb17
3 changed files with 32 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -4559,6 +4559,7 @@ dependencies = [
"antithesis_sdk",
"clap",
"hex",
"rusqlite",
"tempfile",
"tokio",
"tracing",

View File

@@ -30,3 +30,4 @@ tracing = { workspace = true }
tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
turso = { workspace = true }
rusqlite = { workspace = true }

View File

@@ -450,6 +450,31 @@ pub fn init_tracing() -> Result<WorkerGuard, std::io::Error> {
Ok(guard)
}
fn integrity_check(
db_path: &std::path::Path,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
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<String> = 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<dyn std::error::Error + Send + Sync>> {
let _g = init_tracing()?;
@@ -614,5 +639,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
}
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(())
}