Fix key-value store tests (#2130)

This commit is contained in:
Tobie Morgan Hitchcock 2023-06-13 19:01:08 +01:00 committed by GitHub
parent e42c8fdb1a
commit ab5737dd2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 76 deletions

View file

@ -38,7 +38,8 @@ mod rocksdb {
include!("raw.rs");
include!("snapshot.rs");
include!("multireader.rs");
include!("multiwriter.rs");
include!("multiwriter_different_keys.rs");
include!("multiwriter_same_keys_conflict.rs");
}
#[cfg(feature = "kv-speedb")]
@ -61,7 +62,8 @@ mod speedb {
include!("raw.rs");
include!("snapshot.rs");
include!("multireader.rs");
include!("multiwriter.rs");
include!("multiwriter_different_keys.rs");
include!("multiwriter_same_keys_conflict.rs");
}
#[cfg(feature = "kv-tikv")]
@ -88,7 +90,8 @@ mod tikv {
include!("raw.rs");
include!("snapshot.rs");
include!("multireader.rs");
include!("multiwriter.rs");
include!("multiwriter_different_keys.rs");
include!("multiwriter_same_keys_conflict.rs");
}
#[cfg(feature = "kv-fdb")]
@ -115,5 +118,6 @@ mod fdb {
include!("raw.rs");
include!("snapshot.rs");
include!("multireader.rs");
include!("multiwriter.rs");
include!("multiwriter_different_keys.rs");
include!("multiwriter_same_keys_allow.rs");
}

View file

@ -1,72 +0,0 @@
#[tokio::test]
#[serial]
async fn multiwriter_same_key() {
// Create a new datastore
let ds = new_ds().await;
// Insert an initial key
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "some text").await.unwrap();
tx.commit().await.unwrap();
// Create a writeable transaction
let mut tx1 = ds.transaction(true, false).await.unwrap();
tx1.set("test", "other text").await.unwrap();
// Create a writeable transaction
let mut tx2 = ds.transaction(true, false).await.unwrap();
tx2.set("test", "other text").await.unwrap();
// Create a writeable transaction
let mut tx3 = ds.transaction(true, false).await.unwrap();
tx3.set("test", "other text").await.unwrap();
// Cancel both writeable transactions
assert!(tx1.commit().await.is_ok());
assert!(tx2.commit().await.is_err());
assert!(tx3.commit().await.is_err());
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"other text");
tx.cancel().await.unwrap();
// Create a writeable transaction
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "original text").await.unwrap();
tx.commit().await.unwrap();
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"original text");
tx.cancel().await.unwrap();
}
#[tokio::test]
#[serial]
async fn multiwriter_different_keys() {
// Create a new datastore
let ds = new_ds().await;
// Insert an initial key
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "some text").await.unwrap();
tx.commit().await.unwrap();
// Create a writeable transaction
let mut tx1 = ds.transaction(true, false).await.unwrap();
tx1.set("test1", "other text 1").await.unwrap();
// Create a writeable transaction
let mut tx2 = ds.transaction(true, false).await.unwrap();
tx2.set("test2", "other text 2").await.unwrap();
// Create a writeable transaction
let mut tx3 = ds.transaction(true, false).await.unwrap();
tx3.set("test3", "other text 3").await.unwrap();
// Cancel both writeable transactions
tx1.commit().await.unwrap();
tx2.commit().await.unwrap();
tx3.commit().await.unwrap();
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"some text");
let val = tx.get("test1").await.unwrap().unwrap();
assert_eq!(val, b"other text 1");
let val = tx.get("test2").await.unwrap().unwrap();
assert_eq!(val, b"other text 2");
let val = tx.get("test3").await.unwrap().unwrap();
assert_eq!(val, b"other text 3");
tx.cancel().await.unwrap();
}

View file

@ -0,0 +1,34 @@
#[tokio::test]
#[serial]
async fn multiwriter_different_keys() {
// Create a new datastore
let ds = new_ds().await;
// Insert an initial key
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "some text").await.unwrap();
tx.commit().await.unwrap();
// Create a writeable transaction
let mut tx1 = ds.transaction(true, false).await.unwrap();
tx1.set("test1", "other text 1").await.unwrap();
// Create a writeable transaction
let mut tx2 = ds.transaction(true, false).await.unwrap();
tx2.set("test2", "other text 2").await.unwrap();
// Create a writeable transaction
let mut tx3 = ds.transaction(true, false).await.unwrap();
tx3.set("test3", "other text 3").await.unwrap();
// Cancel both writeable transactions
tx1.commit().await.unwrap();
tx2.commit().await.unwrap();
tx3.commit().await.unwrap();
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"some text");
let val = tx.get("test1").await.unwrap().unwrap();
assert_eq!(val, b"other text 1");
let val = tx.get("test2").await.unwrap().unwrap();
assert_eq!(val, b"other text 2");
let val = tx.get("test3").await.unwrap().unwrap();
assert_eq!(val, b"other text 3");
tx.cancel().await.unwrap();
}

View file

@ -0,0 +1,37 @@
#[tokio::test]
#[serial]
async fn multiwriter_same_keys_allow() {
// Create a new datastore
let ds = new_ds().await;
// Insert an initial key
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "some text").await.unwrap();
tx.commit().await.unwrap();
// Create a writeable transaction
let mut tx1 = ds.transaction(true, false).await.unwrap();
tx1.set("test", "other text 1").await.unwrap();
// Create a writeable transaction
let mut tx2 = ds.transaction(true, false).await.unwrap();
tx2.set("test", "other text 2").await.unwrap();
// Create a writeable transaction
let mut tx3 = ds.transaction(true, false).await.unwrap();
tx3.set("test", "other text 3").await.unwrap();
// Cancel both writeable transactions
assert!(tx1.commit().await.is_ok());
assert!(tx2.commit().await.is_ok());
assert!(tx3.commit().await.is_ok());
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"other text 3");
tx.cancel().await.unwrap();
// Create a writeable transaction
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "original text").await.unwrap();
tx.commit().await.unwrap();
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"original text");
tx.cancel().await.unwrap();
}

View file

@ -0,0 +1,37 @@
#[tokio::test]
#[serial]
async fn multiwriter_same_keys_conflict() {
// Create a new datastore
let ds = new_ds().await;
// Insert an initial key
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "some text").await.unwrap();
tx.commit().await.unwrap();
// Create a writeable transaction
let mut tx1 = ds.transaction(true, false).await.unwrap();
tx1.set("test", "other text 1").await.unwrap();
// Create a writeable transaction
let mut tx2 = ds.transaction(true, false).await.unwrap();
tx2.set("test", "other text 2").await.unwrap();
// Create a writeable transaction
let mut tx3 = ds.transaction(true, false).await.unwrap();
tx3.set("test", "other text 3").await.unwrap();
// Cancel both writeable transactions
assert!(tx1.commit().await.is_ok());
assert!(tx2.commit().await.is_err());
assert!(tx3.commit().await.is_err());
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"other text 1");
tx.cancel().await.unwrap();
// Create a writeable transaction
let mut tx = ds.transaction(true, false).await.unwrap();
tx.set("test", "original text").await.unwrap();
tx.commit().await.unwrap();
// Check that the key was updated ok
let mut tx = ds.transaction(false, false).await.unwrap();
let val = tx.get("test").await.unwrap().unwrap();
assert_eq!(val, b"original text");
tx.cancel().await.unwrap();
}