Skip to content

Commit

Permalink
Make a single call to run_pending_tasks to evict as many entries as
Browse files Browse the repository at this point in the history
possible from the cache

Tweak some unit tests.
  • Loading branch information
tatsuya6502 committed Apr 16, 2024
1 parent c6a4d4b commit dfbbe3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5112,11 +5112,12 @@ mod tests {
async fn no_batch_size_limit_on_eviction() {
const MAX_CAPACITY: u64 = 20;

const EVICTION_TIMEOUT: Duration = Duration::from_millis(30);
const EVICTION_TIMEOUT: Duration = Duration::from_nanos(0);
const MAX_LOG_SYNC_REPEATS: u32 = 1;
const EVICTION_BATCH_SIZE: u32 = 1;

let hk_conf = HousekeeperConfig::new(
// Timeout should be ignored when the eviction listener is not provided.
Some(EVICTION_TIMEOUT),
Some(MAX_LOG_SYNC_REPEATS),
Some(EVICTION_BATCH_SIZE),
Expand Down Expand Up @@ -5145,7 +5146,7 @@ mod tests {
cache.run_pending_tasks().await;
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Insert more items the cache.
// Insert more items to the cache.
for i in MAX_CAPACITY..(MAX_CAPACITY * 2) {
let v = format!("v{i}");
cache.insert(i, v).await
Expand All @@ -5163,7 +5164,7 @@ mod tests {
cache.run_pending_tasks().await;
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Now the old keys should be gone.
// Now all the old keys should be gone.
assert!(!cache.contains_key(&0));
assert!(!cache.contains_key(&(MAX_CAPACITY - 1)));
// And the new keys should exist.
Expand Down Expand Up @@ -5222,7 +5223,7 @@ mod tests {
assert_eq!(listener_call_count.load(Ordering::Acquire), 0);
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Insert more items the cache.
// Insert more items to the cache.
for i in MAX_CAPACITY..(MAX_CAPACITY * 2) {
let v = format!("v{i}");
cache.insert(i, v).await
Expand Down
9 changes: 5 additions & 4 deletions src/sync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4802,11 +4802,12 @@ mod tests {
fn no_batch_size_limit_on_eviction() {
const MAX_CAPACITY: u64 = 20;

const EVICTION_TIMEOUT: Duration = Duration::from_millis(30);
const EVICTION_TIMEOUT: Duration = Duration::from_nanos(0);
const MAX_LOG_SYNC_REPEATS: u32 = 1;
const EVICTION_BATCH_SIZE: u32 = 1;

let hk_conf = HousekeeperConfig::new(
// Timeout should be ignored when the eviction listener is not provided.
Some(EVICTION_TIMEOUT),
Some(MAX_LOG_SYNC_REPEATS),
Some(EVICTION_BATCH_SIZE),
Expand Down Expand Up @@ -4835,7 +4836,7 @@ mod tests {
cache.run_pending_tasks();
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Insert more items the cache.
// Insert more items to the cache.
for i in MAX_CAPACITY..(MAX_CAPACITY * 2) {
let v = format!("v{i}");
cache.insert(i, v)
Expand All @@ -4853,7 +4854,7 @@ mod tests {
cache.run_pending_tasks();
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Now the old keys should be gone.
// Now all the old keys should be gone.
assert!(!cache.contains_key(&0));
assert!(!cache.contains_key(&(MAX_CAPACITY - 1)));
// And the new keys should exist.
Expand Down Expand Up @@ -4912,7 +4913,7 @@ mod tests {
assert_eq!(listener_call_count.load(Ordering::Acquire), 0);
assert_eq!(cache.entry_count(), MAX_CAPACITY);

// Insert more items the cache.
// Insert more items to the cache.
for i in MAX_CAPACITY..(MAX_CAPACITY * 2) {
let v = format!("v{i}");
cache.insert(i, v);
Expand Down

0 comments on commit dfbbe3f

Please sign in to comment.