Skip to content

Commit 0b922c2

Browse files
committed
test: add mixed read operations between writes cache test
Mix get, contains_key, first/last_key_value on the same cached nodes between bulk overwrites across multiple rounds.
1 parent abc9dd8 commit 0b922c2

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/btreemap/tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,36 @@ fn cache_partial_iter_then_mutate() {
27662766
});
27672767
}
27682768

2769+
/// Mix different read operations (get, contains_key, first/last_key_value)
2770+
/// on the same cached nodes between writes. Each read uses the cache via
2771+
/// take_or_load_node; the write invalidates via save_node.
2772+
#[test]
2773+
fn cache_mixed_reads_between_writes() {
2774+
run_with_various_cache_sizes(|mut btree: BTreeMap<u64, u64, _>| {
2775+
let n = 300u64;
2776+
for i in 0..n {
2777+
btree.insert(i, i);
2778+
}
2779+
2780+
for round in 0..3u64 {
2781+
// Multiple read types on same tree state.
2782+
for i in 0..n {
2783+
assert!(btree.contains_key(&i), "round {round} contains({i})");
2784+
}
2785+
for i in 0..n {
2786+
assert_eq!(btree.get(&i), Some(i + round * 1000), "round {round} get({i})");
2787+
}
2788+
assert_eq!(btree.first_key_value(), Some((0, round * 1000)));
2789+
assert_eq!(btree.last_key_value(), Some((n - 1, n - 1 + round * 1000)));
2790+
2791+
// Write: overwrite all values.
2792+
for i in 0..n {
2793+
btree.insert(i, i + (round + 1) * 1000);
2794+
}
2795+
}
2796+
});
2797+
}
2798+
27692799
// ---------------------------------------------------------------------------
27702800
// Cached variants of existing tests
27712801
//

0 commit comments

Comments
 (0)