Launch tests in parallel.
This commit is contained in:
parent
b0b795d13b
commit
5ecd7b8bef
@ -9,6 +9,7 @@ use futures::future::FutureExt;
|
|||||||
use organic::compare::run_anonymous_compare;
|
use organic::compare::run_anonymous_compare;
|
||||||
use organic::compare::run_compare_on_file;
|
use organic::compare::run_compare_on_file;
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
|
use tokio::task::JoinError;
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use crate::init_tracing::init_telemetry;
|
use crate::init_tracing::init_telemetry;
|
||||||
@ -100,11 +101,13 @@ pub(crate) enum TestStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestConfig {
|
impl TestConfig {
|
||||||
fn run_test(self) -> BoxFuture<'static, TestResult> {
|
fn run_test(self) -> BoxFuture<'static, Result<TestResult, JoinError>> {
|
||||||
async move {
|
async move {
|
||||||
match self {
|
match self {
|
||||||
TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await),
|
TestConfig::TestLayer(test) => Ok(TestResult::ResultLayer(test.run_test().await?)),
|
||||||
TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await),
|
TestConfig::SingleFile(test) => {
|
||||||
|
Ok(TestResult::SingleFileResult(test.run_test().await?))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.boxed()
|
.boxed()
|
||||||
@ -112,30 +115,34 @@ impl TestConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SingleFile {
|
impl SingleFile {
|
||||||
async fn run_test(self) -> SingleFileResult {
|
async fn run_test(self) -> Result<SingleFileResult, JoinError> {
|
||||||
let _permit = TEST_PERMITS.acquire().await.unwrap();
|
let _permit = TEST_PERMITS.acquire().await.unwrap();
|
||||||
let result = run_compare_on_file(&self.file_path);
|
let result = run_compare_on_file(&self.file_path);
|
||||||
SingleFileResult {
|
Ok(SingleFileResult {
|
||||||
file_path: self.file_path,
|
file_path: self.file_path,
|
||||||
status: if result.is_ok() {
|
status: if result.is_ok() {
|
||||||
TestStatus::Good
|
TestStatus::Good
|
||||||
} else {
|
} else {
|
||||||
TestStatus::Bad
|
TestStatus::Bad
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestLayer {
|
impl TestLayer {
|
||||||
async fn run_test(self) -> ResultLayer {
|
async fn run_test(self) -> Result<ResultLayer, JoinError> {
|
||||||
let mut children = Vec::with_capacity(self.children.len());
|
let running_children: Vec<_> = self
|
||||||
for config in self.children {
|
.children
|
||||||
let result = config.run_test().await;
|
.into_iter()
|
||||||
children.push(result);
|
.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,
|
name: self.name,
|
||||||
children,
|
children,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user