From d6bd5394957f79e0e2f7b5bb741db5dae33722aa Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 30 May 2024 19:00:16 +0000 Subject: [PATCH] test: fix logging of TestContext created using TestContext::new_alice() Before this fix LogSink was dropped immediately, resulting in no logs printed for contexts created using TextContext::new_alice(), but printed for contexts created using TextContext::new(). --- src/test_utils.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index f1b0bbc603..4d0aee65ac 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -193,7 +193,18 @@ impl TestContextManager { #[derive(Debug, Clone, Default)] pub struct TestContextBuilder { key_pair: Option, - log_sink: LogSink, + + /// Log sink if set. + /// + /// If log sink is not set, + /// a new one will be created and stored + /// inside the test context when it is built. + /// If log sink is provided by the caller, + /// it will be subscribed to the test context, + /// but not stored inside of it, + /// so the caller should store the LogSink elsewhere to + /// prevent it from being dropped immediately. + log_sink: Option, } impl TestContextBuilder { @@ -234,7 +245,7 @@ impl TestContextBuilder { /// sequence as they occurred rather than all messages from each context in a single /// block. pub fn with_log_sink(mut self, sink: LogSink) -> Self { - self.log_sink = sink; + self.log_sink = Some(sink); self } @@ -242,7 +253,7 @@ impl TestContextBuilder { pub async fn build(self) -> TestContext { let name = self.key_pair.as_ref().map(|key| key.addr.local.clone()); - let test_context = TestContext::new_internal(name, Some(self.log_sink.clone())).await; + let test_context = TestContext::new_internal(name, self.log_sink).await; if let Some(key_pair) = self.key_pair { test_context