mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-31 05:44:25 +01:00
Run SQLite integrity check after stress test run
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4559,6 +4559,7 @@ dependencies = [
|
||||
"antithesis_sdk",
|
||||
"clap",
|
||||
"hex",
|
||||
"rusqlite",
|
||||
"tempfile",
|
||||
"tokio",
|
||||
"tracing",
|
||||
|
||||
@@ -30,3 +30,4 @@ tracing = { workspace = true }
|
||||
tracing-appender = { workspace = true }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
||||
turso = { workspace = true }
|
||||
rusqlite = { workspace = true }
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user