From 4127e96082eb91e220bc8ba031d3f842510fd4b9 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 14 Apr 2023 09:06:48 -0600 Subject: [PATCH] Reduce the size of proptest-generated history trees. After replacing `quickcheck` with `proptest` in `zcash_history`, memory consumption of the property tests grew substantially as a consequence of sample generation exploring the upper bounds of sample ranges; previously, the large operation counts would have occurred only with low probability. However, the correctness of the operations on the `Tree` data structure should not depend upon the tree size, so it's fine to reduce the number of operations in order to bound the memory consumption. As the documentation on `Tree` notes, this data structure is not intended to be used stand-alone because doing so may result in unbounded memory use; the property tests were doing exactly this and so were producing this exact pathological memory behavior. --- zcash_history/src/tree.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/zcash_history/src/tree.rs b/zcash_history/src/tree.rs index 67b9c2fd3..5d543c738 100644 --- a/zcash_history/src/tree.rs +++ b/zcash_history/src/tree.rs @@ -640,10 +640,8 @@ mod tests { } proptest! { - #![proptest_config(ProptestConfig::with_cases(10))] - #[test] - fn prop_there_and_back(number in 0u32..=(1024*1024)) { + fn prop_there_and_back(number in 0u32..=1024) { let mut tree = initial(); for i in 0..number { tree.append_leaf(leaf(i+3)).expect("Failed to append"); @@ -656,7 +654,7 @@ mod tests { } #[test] - fn prop_leaf_count(number in 3u32..=(1024*1024)) { + fn prop_leaf_count(number in 3u32..=1024) { let mut tree = initial(); for i in 1..(number-1) { tree.append_leaf(leaf(i+2)).expect("Failed to append"); @@ -666,7 +664,7 @@ mod tests { } #[test] - fn prop_parity(number in 3u32..=(2048*2048)) { + fn prop_parity(number in 3u32..=2048) { let mut tree = initial(); for i in 1..(number-1) { tree.append_leaf(leaf(i+2)).expect("Failed to append"); @@ -681,7 +679,7 @@ mod tests { #[test] fn prop_parity_with_truncate( - add_and_delete in (0u32..=(2048*2048)).prop_flat_map( + add_and_delete in (0u32..=2048).prop_flat_map( |add| (Just(add), 0..=add) ) ) { @@ -707,7 +705,7 @@ mod tests { #[test] fn prop_stored_length( - add_and_delete in (0u32..=(2048*2048)).prop_flat_map( + add_and_delete in (0u32..=2048).prop_flat_map( |add| (Just(add), 0..=add) ) ) {