From 5ecd7b8bef512c9532accb8ea5f7b9a541313fbb Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 13 Oct 2023 12:07:52 -0400 Subject: [PATCH] Launch tests in parallel. --- src/bin_foreign_document_test.rs | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/bin_foreign_document_test.rs b/src/bin_foreign_document_test.rs index 4bb471ae..21cb2d01 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, - } + }) } }