Skip to content

Commit d0b51b7

Browse files
committed
feat(aggregator): implement a 'SignatureConsumerNoop' for 'SignatureConsumer' trait
1 parent 11970cf commit d0b51b7

File tree

1 file changed

+43
-0
lines changed
  • mithril-aggregator/src/services/signature_consumer

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use std::future;
2+
3+
use async_trait::async_trait;
4+
5+
use super::SignatureConsumer;
6+
7+
/// A no-op implementation of the [SignatureConsumer] trait that will never return signatures.
8+
#[derive(Default)]
9+
pub struct SignatureConsumerNoop;
10+
11+
#[async_trait]
12+
impl SignatureConsumer for SignatureConsumerNoop {
13+
async fn get_signatures(
14+
&self,
15+
) -> mithril_common::StdResult<
16+
Vec<(
17+
mithril_common::entities::SingleSignature,
18+
mithril_common::entities::SignedEntityType,
19+
)>,
20+
> {
21+
future::pending().await
22+
}
23+
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use anyhow::anyhow;
28+
use tokio::time::{sleep, Duration};
29+
30+
use super::*;
31+
32+
#[tokio::test]
33+
async fn signature_consumer_noop_never_returns() {
34+
let consumer = SignatureConsumerNoop;
35+
36+
let result = tokio::select!(
37+
_res = sleep(Duration::from_millis(100)) => {Err(anyhow!("Timeout"))},
38+
_res = consumer.get_signatures() => {Ok(())},
39+
);
40+
41+
result.expect_err("Should have timed out");
42+
}
43+
}

0 commit comments

Comments
 (0)