From 49325296a9175c5c86dde28e1b4c777be873a188 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 25 Oct 2020 12:20:15 +0100 Subject: [PATCH] Expose query progress information Add unit tests --- src/hooks.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/hooks.rs b/src/hooks.rs index 624ab4b..3cf3527 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -364,4 +364,33 @@ mod test { db.execute_batch("INSERT INTO foo VALUES ('lisa')").unwrap(); assert!(CALLED.load(Ordering::Relaxed)); } + + #[test] + fn test_progress_handler() { + let db = Connection::open_in_memory().unwrap(); + + lazy_static! { + static ref CALLED: AtomicBool = AtomicBool::new(false); + } + db.progress_handler(1, Some(|| { + CALLED.store(true, Ordering::Relaxed); + false + })); + db.execute_batch("BEGIN; CREATE TABLE foo (t TEXT); COMMIT;") + .unwrap(); + assert!(CALLED.load(Ordering::Relaxed)); + } + + #[test] + fn test_progress_handler_interrupt() { + let db = Connection::open_in_memory().unwrap(); + + fn handler() -> bool { + true + } + + db.progress_handler(1, Some(handler)); + db.execute_batch("BEGIN; CREATE TABLE foo (t TEXT); COMMIT;") + .unwrap_err(); + } }