mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-25 14:45:54 -05:00
test behavior of dropped transactions
This addresses one of db.rs's TODOs. No surprises here.
This commit is contained in:
parent
32647e20f5
commit
b15ec58865
28
src/db.rs
28
src/db.rs
@ -430,7 +430,6 @@ struct State {
|
||||
|
||||
/// A high-level transaction. This manages the SQLite transaction and the matching modification to
|
||||
/// be applied to the in-memory state on successful commit.
|
||||
// TODO: requires a drop implementation, or is it sufficient for rusqlite::Transaction to have one?
|
||||
pub struct Transaction<'a> {
|
||||
state: &'a mut State,
|
||||
mods_by_camera: fnv::FnvHashMap<i32, CameraModification>,
|
||||
@ -1214,7 +1213,7 @@ mod tests {
|
||||
assert_eq!(0, db.cameras_by_id().values().count());
|
||||
}
|
||||
|
||||
/// Basic test of the full lifecycle of recording. Does not exercise many error cases.
|
||||
/// Basic test of the full lifecycle of recording. Does not exercise error cases.
|
||||
#[test]
|
||||
fn test_full_lifecycle() {
|
||||
testutil::init_logging();
|
||||
@ -1287,4 +1286,29 @@ mod tests {
|
||||
assert_unsorted_eq(db.lock().list_reserved_sample_files().unwrap(),
|
||||
vec![uuid_to_use, uuid_to_keep]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_drop_tx() {
|
||||
testutil::init_logging();
|
||||
let conn = setup_conn();
|
||||
let db = Database::new(conn).unwrap();
|
||||
let mut db = db.lock();
|
||||
{
|
||||
let mut tx = db.tx().unwrap();
|
||||
tx.reserve_sample_file().unwrap();
|
||||
// drop tx without committing.
|
||||
}
|
||||
|
||||
// The dropped tx should have done nothing.
|
||||
assert_eq!(db.list_reserved_sample_files().unwrap(), &[]);
|
||||
|
||||
// Following transactions should succeed.
|
||||
let uuid;
|
||||
{
|
||||
let mut tx = db.tx().unwrap();
|
||||
uuid = tx.reserve_sample_file().unwrap();
|
||||
tx.commit().unwrap();
|
||||
}
|
||||
assert_eq!(db.list_reserved_sample_files().unwrap(), &[uuid]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user