diff --git a/testing/stress/conn.rs b/testing/stress/conn.rs index 16ed36a7b..1fc8286d5 100644 --- a/testing/stress/conn.rs +++ b/testing/stress/conn.rs @@ -89,6 +89,13 @@ impl StressConn { result } + pub async fn rollback_if_open(&self) -> turso::Result<()> { + if !self.conn.is_autocommit()? { + self.execute("ROLLBACK", ()).await?; + } + Ok(()) + } + pub async fn pragma_update( &self, pragma_name: &str, diff --git a/testing/stress/main.rs b/testing/stress/main.rs index 257764a32..4deb78ea2 100644 --- a/testing/stress/main.rs +++ b/testing/stress/main.rs @@ -813,42 +813,34 @@ async fn async_main(opts: Opts) -> Result<(), Box - { - sql_logger.log(&thread, "PRAGMA integrity_check", "OK"); + let sql = "PRAGMA integrity_check"; + let result: turso::Result> = async { + let mut result_rows = conn.query(sql, ()).await?; + let mut rows = Vec::new(); + while let Some(row) = result_rows.next().await? { + rows.push(row.get_value(0)?); } - Ok(Some(row)) => { - let mut rows = vec![row.get_value(0).unwrap()]; - while let Some(r) = res.next().await? { - rows.push(r.get_value(0).unwrap()); - } - sql_logger.log( - &thread, - "PRAGMA integrity_check", - &format!("ERROR: {rows:?}"), - ); - turso_macros::turso_assert_unreachable!("integrity check failed", { "thread": thread, "rows": rows }); + Ok(rows) + } + .await; + match result { + Ok(rows) if rows == [Value::Text("ok".into())] => { + sql_logger.log(&thread, sql, "OK"); } - Ok(None) => { - sql_logger.log(&thread, "PRAGMA integrity_check", "ERROR: no rows"); + Ok(rows) if rows.is_empty() => { + sql_logger.log(&thread, sql, "ERROR: no rows"); turso_macros::turso_assert_unreachable!("integrity check returned no rows", { "thread": thread }); } + Ok(rows) => { + sql_logger.log(&thread, sql, &format!("ERROR: {rows:?}")); + turso_macros::turso_assert_unreachable!("integrity check failed", { "thread": thread, "rows": rows }); + } Err(turso::Error::Busy(_) | turso::Error::BusySnapshot(_)) => { - sql_logger.log( - &thread, - "PRAGMA integrity_check", - "SKIPPED: database busy", - ); + sql_logger.log(&thread, sql, "SKIPPED: database busy"); + conn.rollback_if_open().await?; } Err(e) => { - sql_logger.log( - &thread, - "PRAGMA integrity_check", - &format!("ERROR: {e}"), - ); + sql_logger.log(&thread, sql, &format!("ERROR: {e}")); turso_macros::turso_assert_unreachable!("Error performing integrity check", { "thread": thread, "error": e }); } } @@ -942,3 +934,41 @@ async fn async_main(opts: Opts) -> Result<(), Box