-
Notifications
You must be signed in to change notification settings - Fork 138
Add proptest support #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1d6f8dc
ed3d1ab
ebe3261
325022e
9021984
b61ccdc
ad34cc4
bc57b20
1198d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. | ||
mod raw; | ||
use std::env::var; | ||
const ENV_PD_ADDR: &str = "PD_ADDR"; | ||
pub fn pd_addr() -> Vec<String> { | ||
var(ENV_PD_ADDR) | ||
.expect(&format!("Expected {}:", ENV_PD_ADDR)) | ||
.split(",") | ||
.map(From::from) | ||
.collect() | ||
} | ||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
mod raw; | ||
|
||
use std::env::var; | ||
const ENV_PD_ADDR: &str = "PD_ADDR"; | ||
|
||
pub fn pd_addr() -> Vec<String> { | ||
var(ENV_PD_ADDR) | ||
.expect(&format!("Expected {}:", ENV_PD_ADDR)) | ||
.split(",") | ||
.map(From::from) | ||
.collect() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. | ||
|
||
use crate::{arb_batch, integration::pd_addr}; | ||
use futures::executor::block_on; | ||
use proptest::{arbitrary::any, proptest}; | ||
use tikv_client::{raw::Client, Config, KvPair, Value}; | ||
|
||
proptest! { | ||
Hoverbear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[test] | ||
fn point( | ||
pair in any::<KvPair>(), | ||
) { | ||
let client = block_on(Client::connect(Config::new(pd_addr()))).unwrap(); | ||
|
||
block_on( | ||
client.put(pair.key().clone(), pair.value().clone()) | ||
).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would too! But, the I'm considering trying to patch this upstream, but in the meantime, this seems easiest as it avoids a fair bit of testrunner/handling boilerplate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking you would just use another function and call that from the test function, but if you think that is not worth the boilerplate, then we can keep things like this |
||
|
||
let out_value = block_on( | ||
client.get(pair.key().clone()) | ||
).unwrap(); | ||
assert_eq!(Some(Value::from(pair.value().clone())), out_value); | ||
|
||
block_on( | ||
client.delete(pair.key().clone()) | ||
).unwrap(); | ||
} | ||
} | ||
|
||
proptest! { | ||
#[test] | ||
fn batch( | ||
kvs in arb_batch(any::<KvPair>(), None), | ||
) { | ||
let client = block_on(Client::connect(Config::new(pd_addr()))).unwrap(); | ||
let keys = kvs.iter().map(|kv| kv.key()).cloned().collect::<Vec<_>>(); | ||
|
||
block_on( | ||
client.batch_put(kvs.clone()) | ||
).unwrap(); | ||
|
||
let out_value = block_on( | ||
client.batch_get(keys.clone()) | ||
).unwrap(); | ||
assert_eq!(kvs, out_value); | ||
|
||
block_on( | ||
client.batch_delete(keys.clone()) | ||
).unwrap(); | ||
} | ||
} | ||
|
||
proptest! { | ||
#[test] | ||
fn scan( | ||
kvs in arb_batch(any::<KvPair>(), None), | ||
) { | ||
let client = block_on(Client::connect(Config::new(pd_addr()))).unwrap(); | ||
let mut keys = kvs.iter().map(|kv| kv.key()).cloned().collect::<Vec<_>>(); | ||
keys.sort(); | ||
// If we aren't getting values this is an empty vector, so use dummy values. | ||
let start_key = keys.iter().cloned().next().unwrap_or(vec![0].into()); | ||
let end_key = keys.iter().cloned().last().unwrap_or(vec![0].into()); | ||
|
||
block_on( | ||
client.batch_put(kvs.clone()) | ||
).unwrap(); | ||
|
||
let out_value = block_on( | ||
client.scan(start_key..=end_key, 10240) // Magic max number is TiKV intrinsic | ||
).unwrap(); | ||
|
||
// Since TiKV returns empty keys as tombstones in scans, we just check we can find all the items. | ||
assert!(kvs.iter().all(|kv| { | ||
out_value.iter().find(|out| kv == *out).is_some() | ||
})); | ||
|
||
block_on( | ||
client.batch_delete(keys.clone()) | ||
).unwrap(); | ||
} | ||
} |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.