diff --git a/tests/fuzz/mod.rs b/tests/fuzz/mod.rs index c096cd20b..40eb360f4 100644 --- a/tests/fuzz/mod.rs +++ b/tests/fuzz/mod.rs @@ -659,7 +659,7 @@ mod fuzz_tests { println!("fk_deferred_constraints_fuzz seed: {seed}"); const OUTER_ITERS: usize = 10; - const INNER_ITERS: usize = 50; + const INNER_ITERS: usize = 100; for outer in 0..OUTER_ITERS { println!("fk_deferred_constraints_fuzz {}/{}", outer + 1, OUTER_ITERS); @@ -743,12 +743,12 @@ mod fuzz_tests { } // Transaction-based mutations with mix of deferred and immediate operations + let mut in_tx = false; for tx_num in 0..INNER_ITERS { // Decide if we're in a transaction - let mut in_tx = false; - let use_transaction = rng.random_bool(0.7); + let start_a_transaction = rng.random_bool(0.7); - if use_transaction && !in_tx { + if start_a_transaction && !in_tx { in_tx = true; let s = log_and_exec("BEGIN"); let sres = sqlite.execute(&s, params![]); @@ -874,7 +874,7 @@ mod fuzz_tests { format!("DELETE FROM child_deferred WHERE id={id}") } // Self-referential deferred insert (create temp violation then fix) - 10 if use_transaction => { + 10 if start_a_transaction => { let id = rng.random_range(400..=500); let pid = id + 1; // References non-existent yet format!("INSERT INTO child_deferred VALUES ({id}, {pid}, 0)") @@ -890,7 +890,7 @@ mod fuzz_tests { let sres = sqlite.execute(&stmt, params![]); let lres = limbo_exec_rows_fallible(&limbo_db, &limbo, &stmt); - if !use_transaction && !in_tx { + if !start_a_transaction && !in_tx { match (sres, lres) { (Ok(_), Ok(_)) | (Err(_), Err(_)) => {} (s, l) => { @@ -908,8 +908,8 @@ mod fuzz_tests { } } - if use_transaction && in_tx { - // Randomly COMMIT or ROLLBACK + // Randomly COMMIT or ROLLBACK some of the time + if in_tx && rng.random_bool(0.4) { let commit = rng.random_bool(0.7); let s = log_and_exec("COMMIT"); @@ -963,8 +963,14 @@ mod fuzz_tests { ); } } + in_tx = false; } } + // Print all statements + if std::env::var("VERBOSE").is_ok() { + println!("{}", stmts.join("\n")); + println!("--------- ITERATION COMPLETED ---------"); + } } }