Skip to content

Commit b26fd62

Browse files
committed
Queries for partial status page data tested
1 parent 1aafc44 commit b26fd62

File tree

3 files changed

+256
-105
lines changed

3 files changed

+256
-105
lines changed

database/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,10 @@ impl BenchmarkJob {
11471147
| BenchmarkJobStatus::Completed { collector_name, .. } => Some(collector_name),
11481148
}
11491149
}
1150+
1151+
pub fn status(&self) -> &BenchmarkJobStatus {
1152+
&self.status
1153+
}
11501154
}
11511155

11521156
/// Describes the final state of a job
@@ -1207,6 +1211,5 @@ impl CollectorConfig {
12071211
#[derive(Debug, PartialEq)]
12081212
pub struct PartialStatusPageData {
12091213
pub completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)>,
1210-
pub in_progress_jobs: Vec<BenchmarkJob>,
1211-
pub in_progress_requests: Vec<BenchmarkRequest>,
1214+
pub in_progress: Vec<(BenchmarkRequest, Vec<BenchmarkJob>)>,
12121215
}

database/src/pool.rs

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ mod tests {
389389
use super::*;
390390
use crate::metric::Metric;
391391
use crate::tests::run_postgres_test;
392+
use crate::BenchmarkJobStatus;
392393
use crate::{tests::run_db_test, BenchmarkRequestType, Commit, CommitType, Date};
393394
use chrono::Utc;
394395
use std::str::FromStr;
@@ -983,6 +984,7 @@ mod tests {
983984
let benchmark_set = BenchmarkSet(0u32);
984985
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
985986
let tag = "sha-1";
987+
let tag_two = "sha-2";
986988
let collector_name = "collector-1";
987989
let target = Target::X86_64UnknownLinuxGnu;
988990

@@ -995,43 +997,117 @@ mod tests {
995997
.await
996998
.unwrap();
997999

998-
/* Create job for the request */
1000+
complete_request(&*db, tag, collector_name, benchmark_set.0, &target).await;
1001+
// record a couple of errors against the tag
1002+
let artifact_id = db.artifact_id(&ArtifactId::Tag(tag.to_string())).await;
1003+
1004+
db.record_error(artifact_id, "example-1", "This is an error")
1005+
.await;
1006+
db.record_error(artifact_id, "example-2", "This is another error")
1007+
.await;
1008+
1009+
let benchmark_request_two = BenchmarkRequest::create_release(tag_two, time);
1010+
db.insert_benchmark_request(&benchmark_request_two)
1011+
.await
1012+
.unwrap();
1013+
9991014
db.enqueue_benchmark_job(
1000-
benchmark_request.tag().unwrap(),
1015+
benchmark_request_two.tag().unwrap(),
10011016
&target,
10021017
&CodegenBackend::Llvm,
10031018
&Profile::Opt,
10041019
benchmark_set.0,
10051020
)
10061021
.await
10071022
.unwrap();
1023+
db.enqueue_benchmark_job(
1024+
benchmark_request_two.tag().unwrap(),
1025+
&target,
1026+
&CodegenBackend::Llvm,
1027+
&Profile::Debug,
1028+
benchmark_set.0,
1029+
)
1030+
.await
1031+
.unwrap();
10081032

1009-
let job = db
1010-
.dequeue_benchmark_job(collector_name, &target, &benchmark_set)
1011-
.await
1012-
.unwrap()
1013-
.unwrap();
1014-
1015-
assert_eq!(job.request_tag(), benchmark_request.tag().unwrap());
1016-
1017-
/* Mark the job as complete */
1018-
db.mark_benchmark_job_as_completed(job.id(), &BenchmarkJobConclusion::Success)
1019-
.await
1020-
.unwrap();
1033+
db.update_benchmark_request_status(
1034+
benchmark_request_two.tag().unwrap(),
1035+
BenchmarkRequestStatus::InProgress,
1036+
)
1037+
.await
1038+
.unwrap();
10211039

1022-
// record a couple of errors against the tag
1023-
let artifact_id = db.artifact_id(&ArtifactId::Tag(tag.to_string())).await;
1040+
let status_page_data = db.get_status_page_data().await.unwrap();
10241041

1025-
db.record_error(artifact_id, "example-1", "This is an error")
1026-
.await;
1027-
db.record_error(artifact_id, "example-2", "This is another error")
1028-
.await;
1042+
assert!(status_page_data.completed_requests.len() == 1);
1043+
assert_eq!(status_page_data.completed_requests[0].0.tag().unwrap(), tag);
1044+
assert!(matches!(
1045+
status_page_data.completed_requests[0].0.status(),
1046+
BenchmarkRequestStatus::Completed { .. }
1047+
));
1048+
// can't really test duration
1049+
// ensure errors are correct
1050+
assert_eq!(
1051+
status_page_data.completed_requests[0].2[0],
1052+
"This is an error".to_string()
1053+
);
1054+
assert_eq!(
1055+
status_page_data.completed_requests[0].2[1],
1056+
"This is another error".to_string()
1057+
);
10291058

1030-
db.mark_benchmark_request_as_completed(tag).await.unwrap();
1059+
assert!(status_page_data.in_progress.len() == 1);
1060+
// we should have 2 jobs
1061+
assert!(status_page_data.in_progress[0].1.len() == 2);
1062+
// the request should be in progress
1063+
assert!(matches!(
1064+
status_page_data.in_progress[0].0.status(),
1065+
BenchmarkRequestStatus::InProgress
1066+
));
10311067

1032-
let status_page_data = db.get_status_page_data().await.unwrap();
1068+
// Test the first job
1069+
assert!(matches!(
1070+
status_page_data.in_progress[0].1[0].target(),
1071+
Target::X86_64UnknownLinuxGnu
1072+
));
1073+
assert!(matches!(
1074+
status_page_data.in_progress[0].1[0].status(),
1075+
BenchmarkJobStatus::Queued
1076+
));
1077+
assert!(matches!(
1078+
status_page_data.in_progress[0].1[0].backend(),
1079+
CodegenBackend::Llvm
1080+
));
1081+
assert!(matches!(
1082+
status_page_data.in_progress[0].1[0].profile(),
1083+
Profile::Opt
1084+
));
1085+
assert_eq!(
1086+
status_page_data.in_progress[0].1[0].benchmark_set(),
1087+
&benchmark_set
1088+
);
10331089

1034-
dbg!("{:?}", status_page_data);
1090+
// test the second job
1091+
assert!(matches!(
1092+
status_page_data.in_progress[0].1[1].target(),
1093+
Target::X86_64UnknownLinuxGnu
1094+
));
1095+
assert!(matches!(
1096+
status_page_data.in_progress[0].1[1].status(),
1097+
BenchmarkJobStatus::Queued
1098+
));
1099+
assert!(matches!(
1100+
status_page_data.in_progress[0].1[1].backend(),
1101+
CodegenBackend::Llvm
1102+
));
1103+
assert!(matches!(
1104+
status_page_data.in_progress[0].1[1].profile(),
1105+
Profile::Debug
1106+
));
1107+
assert_eq!(
1108+
status_page_data.in_progress[0].1[1].benchmark_set(),
1109+
&benchmark_set
1110+
);
10351111

10361112
Ok(ctx)
10371113
})

0 commit comments

Comments
 (0)