Added empty commit.

This commit is contained in:
Jeff Baskin 2023-04-11 08:12:41 -04:00
parent bb23397eb0
commit 448de012d3
1 changed files with 38 additions and 4 deletions

View File

@ -196,6 +196,7 @@ mod datatypes {
#[derive(Debug)] #[derive(Debug)]
enum FromCache { enum FromCache {
Ok,
Data(HashMap<String, DataType>), Data(HashMap<String, DataType>),
Error(MTTError), Error(MTTError),
} }
@ -205,8 +206,29 @@ struct CacheQuery {
reply: Sender<FromCache>, reply: Sender<FromCache>,
} }
struct CacheCommit {
reply: Sender<FromCache>,
}
impl CacheCommit {
fn new(channel: Sender<FromCache>) -> Self {
Self { reply: channel }
}
}
mod commits {
use super::*;
#[test]
fn create() {
let (s, _) = unbounded();
CacheCommit::new(s);
}
}
enum ToCache { enum ToCache {
Query(CacheQuery), Query(CacheQuery),
Commit(CacheCommit),
} }
#[derive(Clone)] #[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()); ids.push(id.to_string());
} }
let (s, r) = unbounded(); let (s, r) = unbounded();
let msg = ToCache::Query( CacheQuery { let msg = ToCache::Query(CacheQuery { ids: ids, reply: s });
ids: ids,
reply: s,
});
channel.send(msg).await.unwrap(); channel.send(msg).await.unwrap();
r.recv().await.unwrap() r.recv().await.unwrap()
} }
@ -329,6 +349,20 @@ mod caches {
_ => assert!(false, "{:?} should have been an error.", result), _ => 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<P>(_dir: P) -> Result<MoreThanText, MTTError> pub async fn start_db<P>(_dir: P) -> Result<MoreThanText, MTTError>