Skip to content

Commit a40d847

Browse files
Potential fixes for 3 code quality findings (#37)
* Apply suggested fix to src/policy/lru.rs from Copilot Autofix * fix tests and test docs that do not align --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
1 parent 3aed617 commit a40d847

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/policy/lru.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@
266266
//! // Touch to mark as recently used without retrieving
267267
//! concurrent_cache.touch(&2);
268268
//!
269-
//! // Type aliases for common patterns
270-
//! use crate::storage::disk::async_disk::cache::lru::BufferPoolCache;
269+
//! // Type alias for a concurrent page cache using this policy
270+
//! type BufferPoolCache<V> = ConcurrentLruCache<u64, V>;
271271
//! let page_cache: BufferPoolCache<Vec<u8>> = BufferPoolCache::new(256);
272272
//! ```
273273
//!
@@ -3757,20 +3757,20 @@ mod tests {
37573757
assert_eq!(cache.recency_rank(&3), Some(0)); // New head
37583758
assert_eq!(cache.recency_rank(&1), Some(1)); // Old item is tail
37593759

3760-
// Test insertion with available capacity (cache capacity is 3, we have 2 items)
3760+
// Test insertion when there is still available capacity (cache capacity is 3, we currently have 2 items)
37613761
cache.insert(4, Arc::new(400));
3762-
assert_eq!(cache.len(), 3); // Should be 3 items now (1, 3, 4)
3763-
assert!(cache.contains(&1)); // Should still be present
3762+
assert_eq!(cache.len(), 3); // Cache should now be at full capacity
3763+
assert!(cache.contains(&1)); // Key 1 is expected to be present before any further evictions
37643764
assert!(cache.contains(&3));
37653765
assert!(cache.contains(&4));
37663766
assert_eq!(cache.recency_rank(&4), Some(0)); // Most recent
37673767
assert_eq!(cache.recency_rank(&3), Some(1)); // Previous head
37683768
assert_eq!(cache.recency_rank(&1), Some(2)); // Least recent (tail)
37693769

3770-
// Now test eviction by inserting another item (5th item, exceeds capacity)
3770+
// Now test eviction by inserting another item (5th distinct key, exceeds capacity)
37713771
cache.insert(5, Arc::new(500));
3772-
assert_eq!(cache.len(), 3); // Should maintain capacity
3773-
assert!(!cache.contains(&1)); // LRU evicted
3772+
assert_eq!(cache.len(), 3); // Cache should remain at its maximum capacity
3773+
assert!(!cache.contains(&1)); // LRU (key 1) should be evicted at this point
37743774
assert!(cache.contains(&3));
37753775
assert!(cache.contains(&4));
37763776
assert!(cache.contains(&5));
@@ -4569,7 +4569,7 @@ mod tests {
45694569
break;
45704570
}
45714571
}
4572-
if !found_rank && i < cache.len() {
4572+
if !found_rank {
45734573
// This should not happen in correct LRU implementation
45744574
panic!("Missing rank {} in steady state", i);
45754575
}

0 commit comments

Comments
 (0)