Skip to content

Commit 4a0a5f9

Browse files
authored
feat: add elapsed time for apply planner (#5)
Signed-off-by: Alex Chi <[email protected]>
1 parent b49c645 commit 4a0a5f9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/apply.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::future::Future;
22
use std::path::Path;
3+
use std::time::{Duration, Instant};
34

45
use anyhow::{anyhow, Context, Error, Result};
56
use console::style;
@@ -29,11 +30,17 @@ where
2930
Ok::<_, Error>((path, testname))
3031
})
3132
.collect::<Result<Vec<_>, _>>()?;
33+
34+
struct TestResult {
35+
testname: String,
36+
time: Duration,
37+
}
3238
let test_stream = stream::iter(tests).map(|(path, testname)| {
3339
let runner_fn = &runner_fn;
3440
let testname_x = testname.clone();
3541
async {
3642
let mut runner = runner_fn().await?;
43+
let start = Instant::now();
3744
tokio::spawn(async move {
3845
let testcases = tokio::fs::read(&path).await?;
3946
let testcases: Vec<TestCase> = serde_yaml::from_slice(&testcases)?;
@@ -53,7 +60,8 @@ where
5360
Ok::<_, Error>(())
5461
})
5562
.await??;
56-
Ok::<_, Error>(testname)
63+
let time = start.elapsed();
64+
Ok::<_, Error>(TestResult { testname, time })
5765
}
5866
.map_err(|e| (e, testname_x))
5967
});
@@ -65,7 +73,12 @@ where
6573
let mut failed_cases = vec![];
6674
while let Some(item) = test_stream.next().await {
6775
match item {
68-
Ok(name) => println!("{} {}", style("[DONE]").green().bold(), name),
76+
Ok(item) => println!(
77+
"{} {}, took {} ms",
78+
style("[DONE]").green().bold(),
79+
item.testname,
80+
item.time.as_millis()
81+
),
6982
Err((e, name)) => {
7083
println!("{} {}: {:#}", style("[FAIL]").red().bold(), name, e);
7184
failed_cases.push(name);

0 commit comments

Comments
 (0)