Skip to content

Commit d944356

Browse files
committed
Make proptest feature more consistent
Signed-off-by: Ana Hobden <[email protected]>
1 parent ebe3261 commit d944356

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

src/kv.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
#[cfg(feature = "proptest-derive")]
3+
#[cfg(feature = "property-testing")]
44
use proptest::{arbitrary::any_with, collection::size_range};
5-
#[cfg(feature = "proptest-derive")]
5+
#[cfg(feature = "property-testing")]
66
use proptest_derive::Arbitrary;
77
use std::ops::{
88
Bound, Deref, DerefMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
99
};
1010
use std::{fmt, str, u8};
1111

12-
#[cfg(feature = "proptest-derive")]
12+
#[cfg(feature = "property-testing")]
1313
const PROPTEST_KEY_MAX: usize = 1024 * 2; // 2 KB
14-
#[cfg(feature = "proptest-derive")]
14+
#[cfg(feature = "property-testing")]
1515
const PROPTEST_VALUE_MAX: usize = 1024 * 16; // 16 KB
1616

1717
use crate::{Error, Result};
@@ -65,10 +65,10 @@ impl<'a> fmt::Display for HexRepr<'a> {
6565
/// accept an `Into<Key>`, which means all of the above types can be passed directly to those
6666
/// functions.
6767
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
68-
#[cfg_attr(feature = "proptest-derive", derive(Arbitrary))]
68+
#[cfg_attr(feature = "property-testing", derive(Arbitrary))]
6969
pub struct Key(
7070
#[cfg_attr(
71-
feature = "proptest-derive",
71+
feature = "property-testing",
7272
proptest(strategy = "any_with::<Vec<u8>>((size_range(PROPTEST_KEY_MAX), ()))")
7373
)]
7474
Vec<u8>,
@@ -186,10 +186,10 @@ impl fmt::Debug for Key {
186186
/// accept an `Into<Value>`, which means all of the above types can be passed directly to those
187187
/// functions.
188188
#[derive(Default, Clone, Eq, PartialEq, Hash)]
189-
#[cfg_attr(feature = "proptest-derive", derive(Arbitrary))]
189+
#[cfg_attr(feature = "property-testing", derive(Arbitrary))]
190190
pub struct Value(
191191
#[cfg_attr(
192-
feature = "proptest-derive",
192+
feature = "property-testing",
193193
proptest(strategy = "any_with::<Vec<u8>>((size_range(PROPTEST_VALUE_MAX), ()))")
194194
)]
195195
Vec<u8>,
@@ -262,7 +262,7 @@ impl fmt::Debug for Value {
262262
/// Many functions which accept a `KvPair` accept an `Into<KvPair>`, which means all of the above
263263
/// types (Like a `(Key, Value)`) can be passed directly to those functions.
264264
#[derive(Default, Clone, Eq, PartialEq)]
265-
#[cfg_attr(feature = "proptest-derive", derive(Arbitrary))]
265+
#[cfg_attr(feature = "property-testing", derive(Arbitrary))]
266266
pub struct KvPair(Key, Value);
267267

268268
impl KvPair {

tests/integration/raw.proptest-regressions

+2
Large diffs are not rendered by default.

tests/integration/raw.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use proptest::{arbitrary::any, proptest};
66
use tikv_client::{raw::Client, Config, KvPair, Value};
77

88
proptest! {
9+
/// Test single point (put, get, delete) operations on keys.
910
#[test]
1011
fn point(
1112
pair in any::<KvPair>(),
@@ -28,6 +29,7 @@ proptest! {
2829
}
2930

3031
proptest! {
32+
/// Test batch (put, get, delete) operations on keys.
3133
#[test]
3234
fn batch(
3335
kvs in arb_batch(any::<KvPair>(), None),
@@ -49,34 +51,3 @@ proptest! {
4951
).unwrap();
5052
}
5153
}
52-
53-
proptest! {
54-
#[test]
55-
fn scan(
56-
kvs in arb_batch(any::<KvPair>(), None),
57-
) {
58-
let client = block_on(Client::connect(Config::new(pd_addr()))).unwrap();
59-
let mut keys = kvs.iter().map(|kv| kv.key()).cloned().collect::<Vec<_>>();
60-
keys.sort();
61-
// If we aren't getting values this is an empty vector, so use dummy values.
62-
let start_key = keys.iter().cloned().next().unwrap_or(vec![0].into());
63-
let end_key = keys.iter().cloned().last().unwrap_or(vec![0].into());
64-
65-
block_on(
66-
client.batch_put(kvs.clone())
67-
).unwrap();
68-
69-
let out_value = block_on(
70-
client.scan(start_key..=end_key, 10240) // Magic max number is TiKV intrinsic
71-
).unwrap();
72-
73-
// Since TiKV returns empty keys as tombstones in scans, we just check we can find all the items.
74-
assert!(kvs.iter().all(|kv| {
75-
out_value.iter().find(|out| kv == *out).is_some()
76-
}));
77-
78-
block_on(
79-
client.batch_delete(keys.clone())
80-
).unwrap();
81-
}
82-
}

tests/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#[cfg(feature = "integration-tests")]
66
mod integration;
77

8-
#[cfg(feature = "proptest")]
8+
#[cfg(feature = "property-testing")]
99
use proptest::strategy::Strategy;
1010

11-
#[cfg(feature = "proptest")]
11+
#[cfg(feature = "property-testing")]
1212
const PROPTEST_BATCH_SIZE_MAX: usize = 16;
1313

14-
#[cfg(feature = "proptest")]
14+
#[cfg(feature = "property-testing")]
1515
pub fn arb_batch<T: core::fmt::Debug>(
1616
single_strategy: impl Strategy<Value = T>,
1717
max_batch_size: impl Into<Option<usize>>,

0 commit comments

Comments
 (0)