Skip to content

Commit

Permalink
Tweak some unit tests for the iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuya6502 committed Apr 10, 2022
1 parent b980670 commit 2f0a316
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ where
/// Creates an iterator visiting all key-value pairs in arbitrary order. The
/// iterator element type is `(Arc<K>, V)`, where `V` is a clone of a stored
/// value.
///
///
/// Iterators do not block concurrent reads and writes on the cache. An entry can
/// be inserted to, invalidated or evicted from a cache while iterators are alive
/// on the same cache.
Expand Down
23 changes: 16 additions & 7 deletions src/sync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,12 @@ mod tests {
assert!(cache.contains_key(&"a"));

mock.increment(Duration::from_secs(5)); // 10 secs.
cache.sync();

assert_eq!(cache.get(&"a"), None);
assert!(!cache.contains_key(&"a"));

assert_eq!(cache.iter().count(), 0);

cache.sync();
assert!(cache.is_table_empty());

cache.insert("b", "bob");
Expand All @@ -1240,12 +1242,15 @@ mod tests {
assert_eq!(cache.estimated_entry_count(), 1);

mock.increment(Duration::from_secs(5)); // 25 secs
cache.sync();

assert_eq!(cache.get(&"a"), None);
assert_eq!(cache.get(&"b"), None);
assert!(!cache.contains_key(&"a"));
assert!(!cache.contains_key(&"b"));

assert_eq!(cache.iter().count(), 0);

cache.sync();
assert!(cache.is_table_empty());
}

Expand Down Expand Up @@ -1291,21 +1296,25 @@ mod tests {
assert_eq!(cache.estimated_entry_count(), 2);

mock.increment(Duration::from_secs(3)); // 15 secs.
cache.sync();

assert_eq!(cache.get(&"a"), None);
assert_eq!(cache.get(&"b"), Some("bob"));
assert!(!cache.contains_key(&"a"));
assert!(cache.contains_key(&"b"));
assert_eq!(cache.estimated_entry_count(), 1);

mock.increment(Duration::from_secs(10)); // 25 secs
assert_eq!(cache.iter().count(), 1);

cache.sync();
assert_eq!(cache.estimated_entry_count(), 1);

mock.increment(Duration::from_secs(10)); // 25 secs
assert_eq!(cache.get(&"a"), None);
assert_eq!(cache.get(&"b"), None);
assert!(!cache.contains_key(&"a"));
assert!(!cache.contains_key(&"b"));

assert_eq!(cache.iter().count(), 0);

cache.sync();
assert!(cache.is_table_empty());
}

Expand Down
4 changes: 4 additions & 0 deletions src/unsync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ mod tests {

assert_eq!(cache.get(&"a"), None);
assert!(!cache.contains_key(&"a"));
assert_eq!(cache.iter().count(), 0);
assert!(cache.cache.is_empty());

cache.insert("b", "bob");
Expand All @@ -1262,6 +1263,7 @@ mod tests {
assert_eq!(cache.get(&"b"), None);
assert!(!cache.contains_key(&"a"));
assert!(!cache.contains_key(&"b"));
assert_eq!(cache.iter().count(), 0);
assert!(cache.cache.is_empty());
}

Expand Down Expand Up @@ -1302,6 +1304,7 @@ mod tests {
assert_eq!(cache.get(&"b"), Some(&"bob"));
assert!(!cache.contains_key(&"a"));
assert!(cache.contains_key(&"b"));
assert_eq!(cache.iter().count(), 1);
assert_eq!(cache.cache.len(), 1);

mock.increment(Duration::from_secs(10)); // 25 secs
Expand All @@ -1310,6 +1313,7 @@ mod tests {
assert_eq!(cache.get(&"b"), None);
assert!(!cache.contains_key(&"a"));
assert!(!cache.contains_key(&"b"));
assert_eq!(cache.iter().count(), 0);
assert!(cache.cache.is_empty());
}

Expand Down

0 comments on commit 2f0a316

Please sign in to comment.