mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
test_utils: implement Deref and DerefMut for EventTracker
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
//! This private module is only compiled for test runs.
|
//! This private module is only compiled for test runs.
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@@ -816,6 +816,20 @@ pub fn fiona_keypair() -> key::KeyPair {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EventTracker(Receiver<Event>);
|
pub struct EventTracker(Receiver<Event>);
|
||||||
|
|
||||||
|
impl Deref for EventTracker {
|
||||||
|
type Target = Receiver<Event>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for EventTracker {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl EventTracker {
|
impl EventTracker {
|
||||||
/// Consumes emitted events returning the first matching one.
|
/// Consumes emitted events returning the first matching one.
|
||||||
///
|
///
|
||||||
@@ -824,7 +838,7 @@ impl EventTracker {
|
|||||||
pub async fn get_matching<F: Fn(&EventType) -> bool>(&self, event_matcher: F) -> EventType {
|
pub async fn get_matching<F: Fn(&EventType) -> bool>(&self, event_matcher: F) -> EventType {
|
||||||
tokio::time::timeout(Duration::from_secs(10), async move {
|
tokio::time::timeout(Duration::from_secs(10), async move {
|
||||||
loop {
|
loop {
|
||||||
let event = self.0.recv().await.unwrap();
|
let event = self.recv().await.unwrap();
|
||||||
if event_matcher(&event.typ) {
|
if event_matcher(&event.typ) {
|
||||||
return event.typ;
|
return event.typ;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user