diff --git a/src/morethantext/cache.rs b/src/morethantext/cache.rs index 0056b72..3cb7366 100644 --- a/src/morethantext/cache.rs +++ b/src/morethantext/cache.rs @@ -41,7 +41,10 @@ impl Cache { } 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 } } diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 6e73459..722df20 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -129,6 +129,23 @@ mod mtt { let store2 = mtt.session().await.unwrap(); 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

(dir: P) -> Result