Skip to content

Commit

Permalink
sort tests by end time
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Jan 7, 2024
1 parent 9ef0ea7 commit 91eee85
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions blade/bep/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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| {
Expand Down
1 change: 1 addition & 0 deletions blade/db/postgres/migrations/2023-11-29-101344_init/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions blade/db/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
},
);
});
Expand All @@ -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);
});
Expand All @@ -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()
Expand All @@ -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| {
Expand Down Expand Up @@ -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![],
};
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions blade/db/postgres/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub struct Test {
pub name: String,
pub status: String,
pub duration_s: Option<f64>,
pub end: String,
pub num_runs: Option<i32>,
}

Expand All @@ -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),
})
Expand All @@ -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),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions blade/db/postgres/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ diesel::table! {
name -> Text,
status -> Text,
duration_s -> Nullable<Float8>,
end -> Text,
num_runs -> Nullable<Int4>,
}
}
Expand Down
1 change: 1 addition & 0 deletions blade/db/sqlite/migrations/2023-11-29-101344_init/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions blade/db/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
},
);
});
Expand All @@ -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()
Expand Down Expand Up @@ -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![],
};
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions blade/db/sqlite/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub struct Test {
pub name: String,
pub status: String,
pub duration_s: Option<f64>,
pub end: String,
pub num_runs: Option<i32>,
}

Expand All @@ -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),
})
Expand All @@ -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),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions blade/db/sqlite/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ diesel::table! {
name -> Text,
status -> Text,
duration_s -> Nullable<Double>,
end -> Text,
num_runs -> Nullable<Integer>,
}
}
Expand Down
1 change: 1 addition & 0 deletions blade/state/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestRun>,
pub num_runs: usize,
}
Expand Down

0 comments on commit 91eee85

Please sign in to comment.