Commit adds db from each session.

This commit is contained in:
Jeff Baskin 2023-06-30 12:23:28 -04:00
parent 05d445c58b
commit e73fdbff75
2 changed files with 21 additions and 1 deletions

View File

@ -41,7 +41,10 @@ impl Cache {
} }
pub fn commit(&mut self, data: Store) -> FromCache { pub fn commit(&mut self, data: Store) -> FromCache {
self.data.insert(ENTRY.to_string(), data).unwrap(); let store = self.data.get_mut(ENTRY).unwrap();
for name in data.list() {
store.add(name).unwrap();
}
FromCache::Ok FromCache::Ok
} }
} }

View File

@ -129,6 +129,23 @@ mod mtt {
let store2 = mtt.session().await.unwrap(); let store2 = mtt.session().await.unwrap();
assert_eq!(store2.list(), [db]); assert_eq!(store2.list(), [db]);
} }
#[async_std::test]
async fn commit_from_multiple_sources() {
let dir = tempdir().unwrap();
let mtt1 = start_db(dir.path()).await.unwrap();
let mtt2 = mtt1.clone();
let db1 = "first";
let db2 = "second";
let mut store1 = mtt1.session().await.unwrap();
let mut store2 = mtt2.session().await.unwrap();
store1.add(db1).unwrap();
store2.add(db2).unwrap();
mtt1.commit(store1).await.unwrap();
mtt2.commit(store2).await.unwrap();
let output = mtt1.session().await.unwrap();
assert_eq!(output.list(), [db1, db2]);
}
} }
pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError> pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError>