From eccc3e23807b5e88b4cdeca660688c5b511684c3 Mon Sep 17 00:00:00 2001 From: Lev Roitman Date: Wed, 26 Jun 2024 16:17:54 +0300 Subject: [PATCH] fix: change ComponentRunner start param to '&mut self' commit-id:6ec10946 --- crates/mempool_infra/src/component_runner.rs | 2 +- crates/mempool_infra/src/component_runner_test.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/mempool_infra/src/component_runner.rs b/crates/mempool_infra/src/component_runner.rs index 19e2d980..11abc1d8 100644 --- a/crates/mempool_infra/src/component_runner.rs +++ b/crates/mempool_infra/src/component_runner.rs @@ -22,5 +22,5 @@ pub trait ComponentCreator { #[async_trait] pub trait ComponentRunner { /// Start the component. Normally this function should never return. - async fn start(&self) -> Result<(), ComponentStartError>; + async fn start(&mut self) -> Result<(), ComponentStartError>; } diff --git a/crates/mempool_infra/src/component_runner_test.rs b/crates/mempool_infra/src/component_runner_test.rs index ceedc8b5..edfcfff8 100644 --- a/crates/mempool_infra/src/component_runner_test.rs +++ b/crates/mempool_infra/src/component_runner_test.rs @@ -48,7 +48,7 @@ mod test_component_a { #[async_trait] impl ComponentRunner for TestComponentA { - async fn start(&self) -> Result<(), ComponentStartError> { + async fn start(&mut self) -> Result<(), ComponentStartError> { println!("TestComponent1::start(), component: {:#?}", self); self.local_start().await.map_err(|_err| ComponentStartError::InternalComponentError) } @@ -87,7 +87,7 @@ mod test_component_b { #[async_trait] impl ComponentRunner for TestComponentB { - async fn start(&self) -> Result<(), ComponentStartError> { + async fn start(&mut self) -> Result<(), ComponentStartError> { println!("TestComponent2::start(): component: {:#?}", self); match self.config.u32_field { 43 => Err(ComponentStartError::InternalComponentError), @@ -103,7 +103,7 @@ use test_component_a::{TestComponentA, TestConfigA}; #[tokio::test] async fn test_component_a() { let test_config = TestConfigA { bool_field: true }; - let component = TestComponentA::create(test_config); + let mut component = TestComponentA::create(test_config); assert_matches!(component.start().await, Ok(())); } @@ -112,17 +112,17 @@ use test_component_b::{TestComponentB, TestConfigB}; #[tokio::test] async fn test_component_b() { let test_config = TestConfigB { u32_field: 42 }; - let component = TestComponentB::create(test_config); + let mut component = TestComponentB::create(test_config); assert_matches!(component.start().await, Ok(())); let test_config = TestConfigB { u32_field: 43 }; - let component = TestComponentB::create(test_config); + let mut component = TestComponentB::create(test_config); assert_matches!(component.start().await, Err(e) => { assert_eq!(e, ComponentStartError::InternalComponentError); }); let test_config = TestConfigB { u32_field: 44 }; - let component = TestComponentB::create(test_config); + let mut component = TestComponentB::create(test_config); assert_matches!(component.start().await, Err(e) => { assert_eq!(e, ComponentStartError::ComponentConfigError); });