File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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//
You can’t perform that action at this time.
0 commit comments