Change kcl_samples tests to run sequentially to make errors easier to understand
This commit is contained in:
@ -2,13 +2,9 @@
|
|||||||
//!
|
//!
|
||||||
//! Use the `KCL_SAMPLES_ONLY=gear` environment variable to run only a subset of
|
//! Use the `KCL_SAMPLES_ONLY=gear` environment variable to run only a subset of
|
||||||
//! the samples, in this case, all those that start with "gear".
|
//! the samples, in this case, all those that start with "gear".
|
||||||
use std::{
|
use std::path::{Path, PathBuf};
|
||||||
collections::HashMap,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use fnv::FnvHashSet;
|
use fnv::FnvHashSet;
|
||||||
use tokio::task::JoinSet;
|
|
||||||
|
|
||||||
use super::Test;
|
use super::Test;
|
||||||
|
|
||||||
@ -66,32 +62,10 @@ async fn kcl_test_execute() {
|
|||||||
|
|
||||||
assert!(!tests.is_empty(), "No KCL samples found");
|
assert!(!tests.is_empty(), "No KCL samples found");
|
||||||
|
|
||||||
// Note: This is unordered.
|
for test in &tests {
|
||||||
let mut tasks = JoinSet::new();
|
super::execute_test(test, true).await;
|
||||||
// Mapping from task ID to test index.
|
|
||||||
let mut id_to_index = HashMap::new();
|
|
||||||
// Spawn a task for each test.
|
|
||||||
for (index, test) in tests.iter().cloned().enumerate() {
|
|
||||||
let handle = tasks.spawn(async move {
|
|
||||||
super::execute_test(&test, true).await;
|
|
||||||
});
|
|
||||||
id_to_index.insert(handle.id(), index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join all the tasks and collect the failures. We cannot just join_all
|
|
||||||
// because insta's error messages don't clearly indicate which test failed.
|
|
||||||
let mut failed = vec![None; tests.len()];
|
|
||||||
while let Some(result) = tasks.join_next().await {
|
|
||||||
let Err(err) = result else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
// When there's an error, store the test name and error message.
|
|
||||||
let index = *id_to_index.get(&err.id()).unwrap();
|
|
||||||
failed[index] = Some(format!("{}: {err}", &tests[index].name));
|
|
||||||
}
|
|
||||||
let failed = failed.into_iter().flatten().collect::<Vec<_>>();
|
|
||||||
assert!(failed.is_empty(), "Failed tests: {}", failed.join("\n"));
|
|
||||||
|
|
||||||
// Ensure that inputs aren't missing.
|
// Ensure that inputs aren't missing.
|
||||||
let input_names = FnvHashSet::from_iter(tests.iter().map(|t| t.name.clone()));
|
let input_names = FnvHashSet::from_iter(tests.iter().map(|t| t.name.clone()));
|
||||||
let missing = expected_outputs
|
let missing = expected_outputs
|
||||||
|
Reference in New Issue
Block a user