test(email): align seen-message tests with HashSet impl
This commit is contained in:
parent
b38797341b
commit
3d8ece4c59
1 changed files with 25 additions and 55 deletions
|
|
@ -412,7 +412,10 @@ impl Channel for EmailChannel {
|
||||||
Ok(Ok(messages)) => {
|
Ok(Ok(messages)) => {
|
||||||
for (id, sender, content, ts) in messages {
|
for (id, sender, content, ts) in messages {
|
||||||
{
|
{
|
||||||
let mut seen = self.seen_messages.lock().expect("seen_messages mutex should not be poisoned");
|
let mut seen = self
|
||||||
|
.seen_messages
|
||||||
|
.lock()
|
||||||
|
.expect("seen_messages mutex should not be poisoned");
|
||||||
if seen.contains(&id) {
|
if seen.contains(&id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -469,63 +472,27 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bounded_seen_set_insert_and_contains() {
|
fn seen_messages_starts_empty() {
|
||||||
let mut set = BoundedSeenSet::new(10);
|
let channel = EmailChannel::new(EmailConfig::default());
|
||||||
assert!(set.insert("a".into()));
|
let seen = channel
|
||||||
assert!(set.contains("a"));
|
.seen_messages
|
||||||
assert!(!set.contains("b"));
|
.lock()
|
||||||
|
.expect("seen_messages mutex should not be poisoned");
|
||||||
|
assert!(seen.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bounded_seen_set_rejects_duplicates() {
|
fn seen_messages_tracks_unique_ids() {
|
||||||
let mut set = BoundedSeenSet::new(10);
|
let channel = EmailChannel::new(EmailConfig::default());
|
||||||
assert!(set.insert("a".into()));
|
let mut seen = channel
|
||||||
assert!(!set.insert("a".into()));
|
.seen_messages
|
||||||
assert_eq!(set.len(), 1);
|
.lock()
|
||||||
}
|
.expect("seen_messages mutex should not be poisoned");
|
||||||
|
|
||||||
#[test]
|
assert!(seen.insert("first-id".to_string()));
|
||||||
fn bounded_seen_set_evicts_oldest_at_capacity() {
|
assert!(!seen.insert("first-id".to_string()));
|
||||||
let mut set = BoundedSeenSet::new(3);
|
assert!(seen.insert("second-id".to_string()));
|
||||||
set.insert("a".into());
|
assert_eq!(seen.len(), 2);
|
||||||
set.insert("b".into());
|
|
||||||
set.insert("c".into());
|
|
||||||
assert_eq!(set.len(), 3);
|
|
||||||
|
|
||||||
set.insert("d".into());
|
|
||||||
assert_eq!(set.len(), 3);
|
|
||||||
assert!(!set.contains("a"), "oldest entry should be evicted");
|
|
||||||
assert!(set.contains("b"));
|
|
||||||
assert!(set.contains("c"));
|
|
||||||
assert!(set.contains("d"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bounded_seen_set_evicts_in_fifo_order() {
|
|
||||||
let mut set = BoundedSeenSet::new(2);
|
|
||||||
set.insert("first".into());
|
|
||||||
set.insert("second".into());
|
|
||||||
set.insert("third".into());
|
|
||||||
assert!(!set.contains("first"));
|
|
||||||
assert!(set.contains("second"));
|
|
||||||
assert!(set.contains("third"));
|
|
||||||
|
|
||||||
set.insert("fourth".into());
|
|
||||||
assert!(!set.contains("second"));
|
|
||||||
assert!(set.contains("third"));
|
|
||||||
assert!(set.contains("fourth"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn bounded_seen_set_capacity_one() {
|
|
||||||
let mut set = BoundedSeenSet::new(1);
|
|
||||||
set.insert("a".into());
|
|
||||||
assert!(set.contains("a"));
|
|
||||||
|
|
||||||
set.insert("b".into());
|
|
||||||
assert!(!set.contains("a"));
|
|
||||||
assert!(set.contains("b"));
|
|
||||||
assert_eq!(set.len(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmailConfig tests
|
// EmailConfig tests
|
||||||
|
|
@ -753,7 +720,10 @@ mod tests {
|
||||||
fn strip_html_handles_malformed() {
|
fn strip_html_handles_malformed() {
|
||||||
assert_eq!(EmailChannel::strip_html("<p>Unclosed"), "Unclosed");
|
assert_eq!(EmailChannel::strip_html("<p>Unclosed"), "Unclosed");
|
||||||
// The function removes everything between < and >, so "Text>with>brackets" becomes "Textwithbrackets"
|
// The function removes everything between < and >, so "Text>with>brackets" becomes "Textwithbrackets"
|
||||||
assert_eq!(EmailChannel::strip_html("Text>with>brackets"), "Textwithbrackets");
|
assert_eq!(
|
||||||
|
EmailChannel::strip_html("Text>with>brackets"),
|
||||||
|
"Textwithbrackets"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue