diff --git a/src/bin_foreign_document_test.rs b/src/bin_foreign_document_test.rs index 4bb471a..21cb2d0 100644 --- a/src/bin_foreign_document_test.rs +++ b/src/bin_foreign_document_test.rs @@ -9,6 +9,7 @@ use futures::future::FutureExt; use organic::compare::run_anonymous_compare; use organic::compare::run_compare_on_file; use tokio::sync::Semaphore; +use tokio::task::JoinError; #[cfg(feature = "tracing")] use crate::init_tracing::init_telemetry; @@ -100,11 +101,13 @@ pub(crate) enum TestStatus { } impl TestConfig { - fn run_test(self) -> BoxFuture<'static, TestResult> { + fn run_test(self) -> BoxFuture<'static, Result> { async move { match self { - TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await), - TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await), + TestConfig::TestLayer(test) => Ok(TestResult::ResultLayer(test.run_test().await?)), + TestConfig::SingleFile(test) => { + Ok(TestResult::SingleFileResult(test.run_test().await?)) + } } } .boxed() @@ -112,30 +115,34 @@ impl TestConfig { } impl SingleFile { - async fn run_test(self) -> SingleFileResult { + async fn run_test(self) -> Result { let _permit = TEST_PERMITS.acquire().await.unwrap(); let result = run_compare_on_file(&self.file_path); - SingleFileResult { + Ok(SingleFileResult { file_path: self.file_path, status: if result.is_ok() { TestStatus::Good } else { TestStatus::Bad }, - } + }) } } impl TestLayer { - async fn run_test(self) -> ResultLayer { - let mut children = Vec::with_capacity(self.children.len()); - for config in self.children { - let result = config.run_test().await; - children.push(result); + async fn run_test(self) -> Result { + let running_children: Vec<_> = self + .children + .into_iter() + .map(|c| tokio::spawn(c.run_test())) + .collect(); + let mut children = Vec::with_capacity(running_children.len()); + for c in running_children { + children.push(c.await??); } - ResultLayer { + Ok(ResultLayer { name: self.name, children, - } + }) } }