Skip to content

Commit

Permalink
using async for implementations in trait
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng committed Feb 26, 2024
1 parent 07ec887 commit f78b8d5
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions crates/stages/src/test_utils/runner.rs
Expand Up @@ -3,7 +3,7 @@ use crate::{ExecInput, ExecOutput, Stage, StageError, StageExt, UnwindInput, Unw
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
use reth_interfaces::db::DatabaseError;
use reth_provider::ProviderError;
use std::{future::Future, sync::Arc};
use std::sync::Arc;
use tokio::sync::oneshot;

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -57,11 +57,8 @@ pub(crate) trait ExecuteStageTestRunner: StageTestRunner {
}

/// Run a hook after [Stage::execute]. Required for Headers & Bodies stages.
fn after_execution(
&self,
_seed: Self::Seed,
) -> impl Future<Output = Result<(), TestRunnerError>> + Send {
async { Ok(()) }
async fn after_execution(&self, _seed: Self::Seed) -> Result<(), TestRunnerError> {
Ok(())
}
}

Expand All @@ -70,10 +67,7 @@ pub(crate) trait UnwindStageTestRunner: StageTestRunner {
fn validate_unwind(&self, input: UnwindInput) -> Result<(), TestRunnerError>;

/// Run [Stage::unwind] and return a receiver for the result.
fn unwind(
&self,
input: UnwindInput,
) -> impl Future<Output = Result<UnwindOutput, StageError>> + Send {
async fn unwind(&self, input: UnwindInput) -> Result<UnwindOutput, StageError> {
let (tx, rx) = oneshot::channel();
let (db, mut stage) = (self.db().factory.clone(), self.stage());
tokio::spawn(async move {
Expand All @@ -82,7 +76,7 @@ pub(crate) trait UnwindStageTestRunner: StageTestRunner {
provider.commit().expect("failed to commit");
tx.send(result).expect("failed to send result");
});
async { rx.await.unwrap() }
rx.await.unwrap()
}

/// Run a hook before [Stage::unwind]. Required for MerkleStage.
Expand Down

0 comments on commit f78b8d5

Please sign in to comment.