diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index afef5c0..acf0d8f 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -196,6 +196,7 @@ mod datatypes { #[derive(Debug)] enum FromCache { + Ok, Data(HashMap), Error(MTTError), } @@ -205,8 +206,29 @@ struct CacheQuery { reply: Sender, } +struct CacheCommit { + reply: Sender, +} + +impl CacheCommit { + fn new(channel: Sender) -> Self { + Self { reply: channel } + } +} + +mod commits { + use super::*; + + #[test] + fn create() { + let (s, _) = unbounded(); + CacheCommit::new(s); + } +} + enum ToCache { Query(CacheQuery), + Commit(CacheCommit), } #[derive(Clone)] @@ -265,6 +287,7 @@ impl Cache { } } } + ToCache::Commit(data) => data.reply.send(FromCache::Ok).await.unwrap(), } } } @@ -294,10 +317,7 @@ mod caches { ids.push(id.to_string()); } let (s, r) = unbounded(); - let msg = ToCache::Query( CacheQuery { - ids: ids, - reply: s, - }); + let msg = ToCache::Query(CacheQuery { ids: ids, reply: s }); channel.send(msg).await.unwrap(); r.recv().await.unwrap() } @@ -329,6 +349,20 @@ mod caches { _ => assert!(false, "{:?} should have been an error.", result), } } + + #[async_std::test] + async fn empty_commit() { + let dir = tempdir().unwrap(); + let s_cache = start_cache(dir.path()).await; + let (s, r) = unbounded(); + let msg = ToCache::Commit(CacheCommit::new(s)); + s_cache.send(msg).await.unwrap(); + let result = r.recv().await.unwrap(); + match result { + FromCache::Ok => (), + _ => assert!(false, "{:?} should have been an error.", result), + } + } } pub async fn start_db

(_dir: P) -> Result