Skip to content

Commit

Permalink
test: memory store basic functionality tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yxonic committed Jun 6, 2022
1 parent 98ca8cf commit 4a174c0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions rcommunity_core/src/store/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,51 @@ impl Transaction for MemoryTransaction {
unimplemented!();
}
}

impl Drop for MemoryTransaction {
fn drop(&mut self) {
// ensure transaction lock is released
self.release_txn_lock();
}
}

#[cfg(test)]
mod test {
use crate::store::{Store, Transaction};

use super::MemoryStore;

#[tokio::test]
async fn test_memory_store() {
let mut store = MemoryStore::default();
{
let mut txn = store.txn_begin().await.unwrap();
assert!(txn.get("key".into()).await.unwrap().is_none());
txn.put("key".into(), "value".into()).await.unwrap();
assert_eq!(
txn.get("key".into()).await.unwrap().unwrap(),
String::from("value")
);
}
{
let mut txn = store.txn_begin().await.unwrap();
assert_eq!(
txn.get_for_update("key".into()).await.unwrap().unwrap(),
String::from("value")
);
txn.put("key".into(), "".into()).await.unwrap();
assert_eq!(
txn.get("key".into()).await.unwrap().unwrap(),
String::from("")
);
txn.commit().await.unwrap();
}
{
let txn = store.txn_begin().await.unwrap();
assert_eq!(
txn.get("key".into()).await.unwrap().unwrap(),
String::from("")
);
}
}
}

0 comments on commit 4a174c0

Please sign in to comment.