Skip to content

Commit ca66ee0

Browse files
committed
master: add test for timed hash map cleanup
1 parent b32bca3 commit ca66ee0

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

master/src/hash_map.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,23 @@ impl<K: Eq + Hash, V> TimedHashMap<K, V> {
130130
})
131131
}
132132
}
133+
134+
#[cfg(test)]
135+
mod tests {
136+
use std::{thread, time::Duration};
137+
138+
use super::*;
139+
140+
#[test]
141+
fn cleanup() {
142+
let n = Periodic::DEFAULT_LIMIT as usize;
143+
let mut map = TimedHashMap::new(1);
144+
for i in (0..3).map(|i| i * n) {
145+
for j in 0..n {
146+
map.insert(i + j, ());
147+
}
148+
assert_eq!(map.len(), n);
149+
thread::sleep(Duration::from_secs(1));
150+
}
151+
}
152+
}

master/src/periodic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ pub struct Periodic<T> {
77
data: T,
88
}
99

10-
impl<T> Periodic<T> {
10+
impl Periodic<()> {
1111
/// Default limit.
1212
pub const DEFAULT_LIMIT: u16 = 100;
13+
}
1314

15+
impl<T> Periodic<T> {
1416
/// Wraps `data` with a default limit.
1517
pub fn new(data: T) -> Self {
16-
Self::with_limit(data, Self::DEFAULT_LIMIT)
18+
Self::with_limit(data, Periodic::DEFAULT_LIMIT)
1719
}
1820

1921
/// Wraps `data`.

0 commit comments

Comments
 (0)