mirror of
https://github.com/isar/rusqlite.git
synced 2025-03-31 19:12:58 +08:00
commit
64fe11ee37
35
src/busy.rs
35
src/busy.rs
@ -80,12 +80,8 @@ impl InnerConnection {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::sync_channel;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{Connection, ErrorCode, Result, TransactionBehavior};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
#[test]
|
||||
fn test_default_busy() -> Result<()> {
|
||||
@ -103,34 +99,6 @@ mod test {
|
||||
tx1.rollback()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // FIXME: unstable
|
||||
fn test_busy_timeout() {
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let path = temp_dir.path().join("test.db3");
|
||||
|
||||
let db2 = Connection::open(&path).unwrap();
|
||||
db2.busy_timeout(Duration::from_secs(1)).unwrap();
|
||||
|
||||
let (rx, tx) = sync_channel(0);
|
||||
let child = thread::spawn(move || {
|
||||
let mut db1 = Connection::open(&path).unwrap();
|
||||
let tx1 = db1
|
||||
.transaction_with_behavior(TransactionBehavior::Exclusive)
|
||||
.unwrap();
|
||||
rx.send(1).unwrap();
|
||||
thread::sleep(Duration::from_millis(100));
|
||||
tx1.rollback().unwrap();
|
||||
});
|
||||
|
||||
assert_eq!(tx.recv().unwrap(), 1);
|
||||
let _ = db2
|
||||
.query_row("PRAGMA schema_version", [], |row| row.get::<_, i32>(0))
|
||||
.expect("unexpected error");
|
||||
|
||||
child.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_busy_handler() -> Result<()> {
|
||||
static CALLED: AtomicBool = AtomicBool::new(false);
|
||||
@ -153,6 +121,7 @@ mod test {
|
||||
let err = db2.prepare("SELECT * FROM t").unwrap_err();
|
||||
assert_eq!(err.sqlite_error_code(), Some(ErrorCode::DatabaseBusy));
|
||||
assert!(CALLED.load(Ordering::Relaxed));
|
||||
db1.busy_handler(None)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user