mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-30 12:01:57 +00:00
add some tests
This commit is contained in:
@@ -21,4 +21,6 @@ thiserror = "1.0.23"
|
|||||||
tokio = { version = "1.0.1", features = ["sync", "fs", "rt", "io-util", "macros"] }
|
tokio = { version = "1.0.1", features = ["sync", "fs", "rt", "io-util", "macros"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
proptest = "1.0.0"
|
||||||
serde = { version = "1.0.118", features = ["rc", "derive"] }
|
serde = { version = "1.0.118", features = ["rc", "derive"] }
|
||||||
|
tokio = { version = "1.0.1", features = ["sync", "fs", "rt", "rt-multi-thread", "io-util", "macros"] }
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
use tokio::runtime::Builder;
|
||||||
|
|
||||||
#[tokio::test]
|
async fn init_test_env() -> PatchDb {
|
||||||
async fn basic() {
|
|
||||||
let db = PatchDb::open("test.db").await.unwrap();
|
let db = PatchDb::open("test.db").await.unwrap();
|
||||||
db.put(
|
db.put(
|
||||||
&JsonPointer::<&'static str>::default(),
|
&JsonPointer::<&'static str>::default(),
|
||||||
@@ -9,18 +10,63 @@ async fn basic() {
|
|||||||
a: "test1".to_string(),
|
a: "test1".to_string(),
|
||||||
b: Child {
|
b: Child {
|
||||||
a: "test2".to_string(),
|
a: "test2".to_string(),
|
||||||
b: 4,
|
b: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await.unwrap();
|
||||||
.unwrap();
|
db
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn put_string_into_root(db: PatchDb, s: String) -> Arc<Revision> {
|
||||||
|
println!("trying string: {}", s);
|
||||||
|
db.put(
|
||||||
|
&JsonPointer::<&'static str>::default(),
|
||||||
|
&s
|
||||||
|
)
|
||||||
|
.await.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn basic() {
|
||||||
|
let db = init_test_env().await;
|
||||||
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
||||||
|
let mut get_res: Value = db.get(&ptr).await.unwrap();
|
||||||
|
assert_eq!(get_res, 1);
|
||||||
db.put(&ptr, &"hello").await.unwrap();
|
db.put(&ptr, &"hello").await.unwrap();
|
||||||
let get_res: Value = db.get(&ptr).await.unwrap();
|
get_res = db.get(&ptr).await.unwrap();
|
||||||
assert_eq!(get_res, "hello");
|
assert_eq!(get_res, "hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn transaction() {
|
||||||
|
let db = init_test_env().await;
|
||||||
|
let mut tx = db.begin();
|
||||||
|
let ptr: JsonPointer = "/b/b".parse().unwrap();
|
||||||
|
tx.put(&ptr, &(2 as usize)).await.unwrap();
|
||||||
|
tx.put(&ptr, &(1 as usize)).await.unwrap();
|
||||||
|
let _res = tx.commit().await.unwrap();
|
||||||
|
println!("res = {:?}", _res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#[test]
|
||||||
|
fn doesnt_crash(s in "\\PC*") {
|
||||||
|
// build runtime
|
||||||
|
let runtime = Builder::new_multi_thread()
|
||||||
|
.worker_threads(4)
|
||||||
|
.thread_name("test-doesnt-crash")
|
||||||
|
.thread_stack_size(3 * 1024 * 1024)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let db = runtime.block_on(init_test_env());
|
||||||
|
let put_future = put_string_into_root(db, s);
|
||||||
|
runtime.block_on(put_future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Sample {
|
pub struct Sample {
|
||||||
a: String,
|
a: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user