Skip to content

Commit

Permalink
fix: change ComponentRunner start param to '&mut self'
Browse files Browse the repository at this point in the history
commit-id:6ec10946
  • Loading branch information
lev-starkware committed Jun 26, 2024
1 parent 1ba1c91 commit bb0e379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/mempool_infra/src/component_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub trait ComponentCreator<T: SerializeConfig> {
#[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>;
}
12 changes: 6 additions & 6 deletions crates/mempool_infra/src/component_runner_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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),
Expand All @@ -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(()));
}

Expand All @@ -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);
});
Expand Down

0 comments on commit bb0e379

Please sign in to comment.