diff --git a/blade/bep/target.rs b/blade/bep/target.rs index 1491ea3..5b9e286 100644 --- a/blade/bep/target.rs +++ b/blade/bep/target.rs @@ -143,6 +143,7 @@ impl crate::EventHandler for Handler { summary.first_start_time.as_ref(), summary.last_stop_time.as_ref(), ), + end: std::time::SystemTime::now(), runs: Default::default(), num_runs: summary.run_count as usize, }; @@ -160,6 +161,7 @@ impl crate::EventHandler for Handler { duration: Default::default(), num_runs: 0, runs: vec![], + end: std::time::SystemTime::now(), status: state::Status::InProgress, }); r.test_action_output.iter().for_each(|f| { diff --git a/blade/db/postgres/migrations/2023-11-29-101344_init/up.sql b/blade/db/postgres/migrations/2023-11-29-101344_init/up.sql index b43a4fd..c8e4390 100644 --- a/blade/db/postgres/migrations/2023-11-29-101344_init/up.sql +++ b/blade/db/postgres/migrations/2023-11-29-101344_init/up.sql @@ -26,6 +26,7 @@ CREATE TABLE Tests ( name TEXT NOT NULL, status TEXT NOT NULL, duration_s double precision, + "end" TEXT NOT NULl, num_runs INTEGER, FOREIGN KEY(invocation_id) REFERENCES Invocations(id) ON DELETE CASCADE diff --git a/blade/db/postgres/mod.rs b/blade/db/postgres/mod.rs index a894eb3..720c9e2 100644 --- a/blade/db/postgres/mod.rs +++ b/blade/db/postgres/mod.rs @@ -142,11 +142,11 @@ impl state::DB for Postgres { name: res.name.clone(), status: state::Status::parse(&res.status), kind: res.kind.clone(), - start: parse_time(&res.start) - .unwrap_or_else(|_| std::time::SystemTime::now()), - end: res.end.as_ref().map(|t| { - parse_time(t).unwrap_or_else(|_| std::time::SystemTime::now()) - }), + start: parse_time(&res.start).unwrap_or_else(|_| std::time::SystemTime::now()), + end: res + .end + .as_ref() + .map(|t| parse_time(t).unwrap_or_else(|_| std::time::SystemTime::now())), }, ); }); @@ -164,7 +164,8 @@ impl state::DB for Postgres { .select(models::TestArtifact::as_select()) .filter(schema::testartifacts::dsl::invocation_id.eq(id)) .load(&mut self.conn)? - .into_iter().for_each(|a: models::TestArtifact| { + .into_iter() + .for_each(|a: models::TestArtifact| { let v = test_artifacts.entry(a.test_run_id.clone()).or_default(); v.push(a); }); @@ -176,6 +177,7 @@ impl state::DB for Postgres { name: test.name, status: state::Status::parse(&test.status), duration: std::time::Duration::from_secs_f64(test.duration_s.unwrap_or(0.0)), + end: parse_time(&test.end).unwrap_or_else(|_| std::time::SystemTime::now()), num_runs: test.num_runs.map(|nr| nr as usize).unwrap_or(0), runs: trs .into_iter() @@ -186,7 +188,8 @@ impl state::DB for Postgres { status: state::Status::parse(&tr.status), details: tr.details, duration: std::time::Duration::from_secs_f64(tr.duration_s), - files: test_artifacts.get_mut(&tr.id) + files: test_artifacts + .get_mut(&tr.id) .map(|v| { v.drain(..) .map(|ta| { @@ -425,6 +428,7 @@ mod tests { name: "//target/path:thing".to_string(), status: state::Status::InProgress, duration: std::time::Duration::from_secs_f64(4.343), + end: std::time::SystemTime::now(), num_runs: 0, runs: vec![], }; @@ -507,6 +511,7 @@ mod tests { status: state::Status::Fail, duration: std::time::Duration::from_secs(5), num_runs: 2, + end: std::time::SystemTime::now(), runs: vec![ state::TestRun { run: 1, diff --git a/blade/db/postgres/models.rs b/blade/db/postgres/models.rs index 726f1b4..f686e4f 100644 --- a/blade/db/postgres/models.rs +++ b/blade/db/postgres/models.rs @@ -139,6 +139,7 @@ pub struct Test { pub name: String, pub status: String, pub duration_s: Option, + pub end: String, pub num_runs: Option, } @@ -152,6 +153,7 @@ impl Test { invocation_id: invocation_id.to_string(), name: t.name.clone(), status: t.status.to_string(), + end: format_time(&t.end)?, duration_s: Some(t.duration.as_secs_f64()), num_runs: Some(t.num_runs as i32), }) @@ -164,6 +166,7 @@ impl Test { num_runs: self.num_runs.unwrap_or(0) as usize, runs: vec![], status: state::Status::parse(&self.status), + end: super::parse_time(&self.end).unwrap_or(UNIX_EPOCH), } } } diff --git a/blade/db/postgres/schema.rs b/blade/db/postgres/schema.rs index 439a15d..dca0570 100644 --- a/blade/db/postgres/schema.rs +++ b/blade/db/postgres/schema.rs @@ -54,6 +54,7 @@ diesel::table! { name -> Text, status -> Text, duration_s -> Nullable, + end -> Text, num_runs -> Nullable, } } diff --git a/blade/db/sqlite/migrations/2023-11-29-101344_init/up.sql b/blade/db/sqlite/migrations/2023-11-29-101344_init/up.sql index 41bf1e0..23508d9 100644 --- a/blade/db/sqlite/migrations/2023-11-29-101344_init/up.sql +++ b/blade/db/sqlite/migrations/2023-11-29-101344_init/up.sql @@ -26,6 +26,7 @@ CREATE TABLE Tests ( name TEXT NOT NULL, status TEXT NOT NULL, duration_s Double, + end TEXT NOT NULL, num_runs INTEGER, FOREIGN KEY(invocation_id) REFERENCES Invocations(id) ON DELETE CASCADE diff --git a/blade/db/sqlite/mod.rs b/blade/db/sqlite/mod.rs index 2f59efa..fa10b26 100644 --- a/blade/db/sqlite/mod.rs +++ b/blade/db/sqlite/mod.rs @@ -146,11 +146,11 @@ impl state::DB for Sqlite { name: res.name.clone(), status: state::Status::parse(&res.status), kind: res.kind.clone(), - start: parse_time(&res.start) - .unwrap_or_else(|_| std::time::SystemTime::now()), - end: res.end.as_ref().map(|t| { - parse_time(t).unwrap_or_else(|_| std::time::SystemTime::now()) - }), + start: parse_time(&res.start).unwrap_or_else(|_| std::time::SystemTime::now()), + end: res + .end + .as_ref() + .map(|t| parse_time(t).unwrap_or_else(|_| std::time::SystemTime::now())), }, ); }); @@ -177,6 +177,7 @@ impl state::DB for Sqlite { name: test.name, status: state::Status::parse(&test.status), duration: std::time::Duration::from_secs_f64(test.duration_s.unwrap_or(0.0)), + end: parse_time(&test.end).unwrap_or_else(|_| std::time::SystemTime::now()), num_runs: test.num_runs.map(|nr| nr as usize).unwrap_or(0), runs: trs .into_iter() @@ -423,6 +424,7 @@ mod tests { name: "//target/path:thing".to_string(), status: state::Status::InProgress, duration: std::time::Duration::from_secs_f64(4.343), + end: std::time::SystemTime::now(), num_runs: 0, runs: vec![], }; @@ -503,6 +505,7 @@ mod tests { name: "//target1:some_test".to_string(), status: state::Status::Fail, duration: std::time::Duration::from_secs(5), + end: std::time::SystemTime::now(), num_runs: 2, runs: vec![ state::TestRun { diff --git a/blade/db/sqlite/models.rs b/blade/db/sqlite/models.rs index a866267..829143f 100644 --- a/blade/db/sqlite/models.rs +++ b/blade/db/sqlite/models.rs @@ -142,6 +142,7 @@ pub struct Test { pub name: String, pub status: String, pub duration_s: Option, + pub end: String, pub num_runs: Option, } @@ -155,6 +156,7 @@ impl Test { invocation_id: invocation_id.to_string(), name: t.name.clone(), status: t.status.to_string(), + end: format_time(&t.end)?, duration_s: Some(t.duration.as_secs_f64()), num_runs: Some(t.num_runs as i32), }) @@ -167,6 +169,7 @@ impl Test { num_runs: self.num_runs.unwrap_or(0) as usize, runs: vec![], status: state::Status::parse(&self.status), + end: super::parse_time(&self.end).unwrap_or(UNIX_EPOCH), } } } diff --git a/blade/db/sqlite/schema.rs b/blade/db/sqlite/schema.rs index 179543e..aebc14c 100644 --- a/blade/db/sqlite/schema.rs +++ b/blade/db/sqlite/schema.rs @@ -54,6 +54,7 @@ diesel::table! { name -> Text, status -> Text, duration_s -> Nullable, + end -> Text, num_runs -> Nullable, } } diff --git a/blade/state/lib.rs b/blade/state/lib.rs index 7ae9fbd..80f7d93 100644 --- a/blade/state/lib.rs +++ b/blade/state/lib.rs @@ -62,6 +62,7 @@ pub struct Test { pub name: String, pub status: Status, pub duration: std::time::Duration, + pub end: std::time::SystemTime, pub runs: Vec, pub num_runs: usize, }