Explicit check that rusqlite::Transaction isn't auto-commited on drop

This commit is contained in:
dbr 2021-04-29 10:58:34 +10:00
parent 23531d73c4
commit a3c9a76f1d

View file

@ -350,6 +350,35 @@ mod test {
use crate::storage::taskmap_with;
use tempfile::TempDir;
#[test]
fn drop_transaction() -> anyhow::Result<()> {
let tmp_dir = TempDir::new()?;
let mut storage = SqliteStorage::new(&tmp_dir.path())?;
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();
{
let mut txn = storage.txn()?;
assert!(txn.create_task(uuid1)?);
txn.commit()?;
}
{
let mut txn = storage.txn()?;
assert!(txn.create_task(uuid2)?);
std::mem::drop(txn); // Unnecessary explicit drop of transaction
}
{
let mut txn = storage.txn()?;
let uuids = txn.all_task_uuids()?;
assert_eq!(uuids, [uuid1]);
}
Ok(())
}
#[test]
fn test_create() -> anyhow::Result<()> {
let tmp_dir = TempDir::new()?;