From 7b1b37095d5a0d32e52ee1d1e872229329b35f10 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 13 Oct 2025 09:09:07 +0300 Subject: [PATCH] stress: Add busy timeout support with 5 second default Add `--busy-timeout` command-line option to turso-stress with a default value of 5000 ms. This helps prevent spurious database busy errors during concurrent stress testing and ensure that integrity checks are not skipped because of concurrent writes. --- stress/main.rs | 6 ++++++ stress/opts.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/stress/main.rs b/stress/main.rs index 5091bd05b..f2ec5a179 100644 --- a/stress/main.rs +++ b/stress/main.rs @@ -493,6 +493,8 @@ async fn main() -> Result<(), Box> { let plan = plan.clone(); let conn = db.lock().await.connect()?; + conn.busy_timeout(std::time::Duration::from_millis(opts.busy_timeout))?; + conn.execute("PRAGMA data_sync_retry = 1", ()).await?; // Apply each DDL statement individually @@ -525,6 +527,8 @@ async fn main() -> Result<(), Box> { let handle = tokio::spawn(async move { let mut conn = db.lock().await.connect()?; + conn.busy_timeout(std::time::Duration::from_millis(opts.busy_timeout))?; + conn.execute("PRAGMA data_sync_retry = 1", ()).await?; println!("\rExecuting queries..."); @@ -542,6 +546,7 @@ async fn main() -> Result<(), Box> { } *db_guard = builder.build().await?; conn = db_guard.connect()?; + conn.busy_timeout(std::time::Duration::from_millis(opts.busy_timeout))?; } else if gen_bool(0.0) { // disabled // Reconnect to the database @@ -550,6 +555,7 @@ async fn main() -> Result<(), Box> { } let db_guard = db.lock().await; conn = db_guard.connect()?; + conn.busy_timeout(std::time::Duration::from_millis(opts.busy_timeout))?; } let sql = &plan.queries_per_thread[thread][query_index]; if !opts.silent { diff --git a/stress/opts.rs b/stress/opts.rs index fd53d7635..796f85847 100644 --- a/stress/opts.rs +++ b/stress/opts.rs @@ -66,4 +66,12 @@ pub struct Opts { /// Number of tables to use #[clap(long, help = "Select number of tables to create")] pub tables: Option, + + /// Busy timeout in milliseconds + #[clap( + long, + help = "Set busy timeout in milliseconds", + default_value_t = 5000 + )] + pub busy_timeout: u64, }