Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add elapsed time for apply planner #5

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/apply.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::future::Future;
use std::path::Path;
use std::time::{Duration, Instant};

use anyhow::{anyhow, Context, Error, Result};
use console::style;
Expand Down Expand Up @@ -29,11 +30,17 @@ where
Ok::<_, Error>((path, testname))
})
.collect::<Result<Vec<_>, _>>()?;

struct TestResult {
testname: String,
time: Duration,
}
let test_stream = stream::iter(tests).map(|(path, testname)| {
let runner_fn = &runner_fn;
let testname_x = testname.clone();
async {
let mut runner = runner_fn().await?;
let start = Instant::now();
tokio::spawn(async move {
let testcases = tokio::fs::read(&path).await?;
let testcases: Vec<TestCase> = serde_yaml::from_slice(&testcases)?;
Expand All @@ -53,7 +60,8 @@ where
Ok::<_, Error>(())
})
.await??;
Ok::<_, Error>(testname)
let time = start.elapsed();
Ok::<_, Error>(TestResult { testname, time })
}
.map_err(|e| (e, testname_x))
});
Expand All @@ -65,7 +73,12 @@ where
let mut failed_cases = vec![];
while let Some(item) = test_stream.next().await {
match item {
Ok(name) => println!("{} {}", style("[DONE]").green().bold(), name),
Ok(item) => println!(
"{} {}, took {} ms",
style("[DONE]").green().bold(),
item.testname,
item.time.as_millis()
),
Err((e, name)) => {
println!("{} {}: {:#}", style("[FAIL]").red().bold(), name, e);
failed_cases.push(name);
Expand Down
Loading