Remove EventSink from TestContext to simplify it

This replaces the EventSink callbacks with simple channel senders.
This simplifies the TestContext a lot as that is much simpler to
handle.  It then also removes the special-casing of the LogSink since
it now is another even sender, only injected at the very start.
This commit is contained in:
Floris Bruynooghe
2021-12-12 21:31:25 +01:00
parent f0ca50ba27
commit 147f5c1e0d
4 changed files with 117 additions and 142 deletions

View File

@@ -678,11 +678,12 @@ async fn prune_tombstones(sql: &Sql) -> Result<()> {
}
#[cfg(test)]
mod test {
mod tests {
use async_std::channel;
use async_std::fs::File;
use crate::config::Config;
use crate::{test_utils::TestContext, Event, EventType};
use crate::{test_utils::TestContext, EventType};
use super::*;
@@ -743,18 +744,8 @@ mod test {
.await
.unwrap();
t.add_event_sink(move |event: Event| async move {
match event.typ {
EventType::Info(s) => assert!(
!s.contains("Keeping new unreferenced file"),
"File {} was almost deleted, only reason it was kept is that it was created recently (as the tests don't run for a long time)",
s
),
EventType::Error(s) => panic!("{}", s),
_ => {}
}
})
.await;
let (event_sink, event_source) = channel::unbounded();
t.add_event_sender(event_sink).await;
let a = t.get_config(Config::Selfavatar).await.unwrap().unwrap();
assert_eq!(avatar_bytes, &async_std::fs::read(&a).await.unwrap()[..]);
@@ -765,6 +756,18 @@ mod test {
let a = t.get_config(Config::Selfavatar).await.unwrap().unwrap();
assert_eq!(avatar_bytes, &async_std::fs::read(&a).await.unwrap()[..]);
while let Ok(event) = event_source.try_recv() {
match event.typ {
EventType::Info(s) => assert!(
!s.contains("Keeping new unreferenced file"),
"File {} was almost deleted, only reason it was kept is that it was created recently (as the tests don't run for a long time)",
s
),
EventType::Error(s) => panic!("{}", s),
_ => {}
}
}
}
/// Regression test.