use crate::{ManagedConnection, SQLiteCompressionOptions};
#[test]
fn the_commit_monitor_changes_with_each_commit_of_another_connection_and_only_then() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("commit-monitor.db");
let observer = ManagedConnection::open(&path).unwrap();
let writer = observer.new_session();
let other_process = ManagedConnection::open(&path).unwrap();
let before = observer.commit_monitor_version().unwrap().unwrap();
assert_eq!(observer.commit_monitor_version().unwrap(), Some(before));
assert_eq!(writer.commit_monitor_version().unwrap(), Some(before));
writer
.with(|connection| {
connection.execute_batch("CREATE TABLE committed (id INTEGER PRIMARY KEY)")?;
Ok(())
})
.unwrap();
let created = observer.commit_monitor_version().unwrap().unwrap();
assert_ne!(created, before);
writer
.with(|connection| {
connection.query_row("SELECT count(*) FROM committed", [], |row| {
row.get::<_, i64>(0)
})?;
Ok(())
})
.unwrap();
other_process.begin_transaction().unwrap();
other_process
.with(|connection| {
connection.execute("INSERT INTO committed (id) VALUES (1)", [])?;
Ok(())
})
.unwrap();
assert_eq!(observer.commit_monitor_version().unwrap(), Some(created));
other_process.commit_transaction().unwrap();
let inserted = observer.commit_monitor_version().unwrap().unwrap();
assert_ne!(inserted, created);
assert_eq!(writer.commit_monitor_version().unwrap(), Some(inserted));
let compressed = ManagedConnection::open_compressed(
&directory.path().join("commit-monitor-compressed.db"),
SQLiteCompressionOptions::default(),
)
.unwrap();
assert_eq!(compressed.commit_monitor_version().unwrap(), None);
let memory = ManagedConnection::open_in_memory().unwrap();
assert_eq!(memory.commit_monitor_version().unwrap(), None);
}