Skip to content

Commit

Permalink
Use prop_filter to force directory treenode (#1227)
Browse files Browse the repository at this point in the history
On my machine, proptest generation has slowed down (now ~40 seconds to
run 30 proptests, before ~16 seconds) significantly. This change
(hopefully) keeps the behaviour identical and restores the speed we
roughly had before.

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and I agree to the terms of
the [Developer Certificate of Origin
(DCO)](https://developercertificate.org/).

Signed-off-by: Christian Hagemeier <[email protected]>
  • Loading branch information
c-hagem authored Jan 14, 2025
1 parent ab77aaa commit 5807eb1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mountpoint-s3/tests/reftests/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ impl Debug for TreeNode {
/// Parents are always [TreeNode::Directory].
pub fn gen_tree(depth: u32, max_size: u32, max_items: u32, max_width: usize) -> impl Strategy<Value = TreeNode> {
let leaf = any::<FileContent>().prop_map(TreeNode::File);

let strategy = leaf.prop_recursive(
leaf.prop_recursive(
depth, // levels
max_size, // max number of nodes
max_items, // number of items per collection
Expand All @@ -138,10 +137,12 @@ pub fn gen_tree(depth: u32, max_size: u32, max_items: u32, max_width: usize) ->
// Since the size of the tree could be zero, this also introduces directories as leaves.
prop::collection::btree_map(any::<Name>(), inner, 0..max_width).prop_map(TreeNode::Directory)
},
);

// Ensure the root is always a directory by wrapping the inner strategy
prop::collection::btree_map(any::<Name>(), strategy, 0..max_width).prop_map(TreeNode::Directory)
)
// Ensure the root is always a directory by transforming invalid nodes (i.e. file as root) into empty directories
.prop_map(|x| match x {
TreeNode::File(_) => TreeNode::Directory(BTreeMap::from([])),
_ => x,
})
}

/// Take a generated tree and create the corresponding S3 namespace (list of keys)
Expand Down

0 comments on commit 5807eb1

Please sign in to comment.