Skip to content

Commit

Permalink
feat: add elapsed time for apply planner
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <iskyzh@gmail.com>
  • Loading branch information
skyzh committed Oct 26, 2024
1 parent b49c645 commit e3777f0
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit e3777f0

Please sign in to comment.