Skip to content

Commit

Permalink
test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
assafvayner committed Oct 2, 2024
1 parent 3be9a27 commit 5ebb2ad
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions chunk_cache/src/disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,20 @@ mod tests {

for start in range.start..range.end {
for end in (start + 1)..=range.end {
assert!(
cache.get(&key, &Range { start, end }).unwrap().is_some(),
"range: [{start} {end})"
);
let get_result = cache.get(&key, &Range { start, end }).unwrap();
assert!(get_result.is_some(), "range: [{start} {end})");
let data_portion = get_data(&Range { start, end }, &chunk_byte_indicies, &data);
assert_eq!(data_portion, get_result.unwrap())
}
}
}

fn get_data<'a>(range: &Range, chunk_byte_indicies: &[u32], data: &'a [u8]) -> &'a [u8] {
let start = chunk_byte_indicies[range.start as usize] as usize;
let end = chunk_byte_indicies[range.end as usize] as usize;
&data[start..end]
}

#[test]
fn test_puts_eviction() {
const CAP: u64 = (RANGE_LEN * 4) as u64;
Expand Down Expand Up @@ -550,13 +556,14 @@ mod tests {
while get_result_1.is_some() && i < 10 {
i += 1;
let (key2, range2, chunk_byte_indicies2, data2) = RandomEntryIterator.next().unwrap();
assert!(cache2
cache2
.put(&key2, &range2, &chunk_byte_indicies2, &data2)
.is_ok());
.unwrap();
get_result_1 = cache2.get(&key, &range).unwrap();
}
if get_result_1.is_some() {
// randomness didn't evict the record after 10 tries, don't test this case now
return;
}
// we've evicted the original record from the cache
// note using the original cache handle without updates!
Expand Down

0 comments on commit 5ebb2ad

Please sign in to comment.