Skip to content

Commit 7be3e39

Browse files
committed
statisfied that ARRAY_AGG(...) can be used
1 parent 46c724c commit 7be3e39

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

database/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ impl CollectorConfig {
12171217
/// status page
12181218
#[derive(Debug, PartialEq)]
12191219
pub struct PartialStatusPageData {
1220-
pub completed_requests: Vec<(BenchmarkRequest, u64, Vec<String>)>,
1220+
pub completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)>,
12211221
pub in_progress_jobs: Vec<BenchmarkJob>,
12221222
pub in_progress_requests: Vec<BenchmarkRequest>,
12231223
}

database/src/pool.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,13 +984,63 @@ mod tests {
984984
.await;
985985
}
986986

987+
#[tokio::test]
987988
async fn get_status_page_data() {
988989
run_postgres_test(|ctx| async {
989990
let db = ctx.db_client().connection().await;
990-
db.add_collector_config("collector-1", &Target::X86_64UnknownLinuxGnu, 1, true)
991+
let benchmark_set = BenchmarkSet(0u32);
992+
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
993+
let tag = "sha-1";
994+
let collector_name = "collector-1";
995+
let target = Target::X86_64UnknownLinuxGnu;
996+
997+
db.add_collector_config(collector_name, &target, benchmark_set.0, true)
998+
.await
999+
.unwrap();
1000+
1001+
let benchmark_request = BenchmarkRequest::create_release(tag, time);
1002+
db.insert_benchmark_request(&benchmark_request)
1003+
.await
1004+
.unwrap();
1005+
1006+
/* Create job for the request */
1007+
db.enqueue_benchmark_job(
1008+
benchmark_request.tag().unwrap(),
1009+
&target,
1010+
&CodegenBackend::Llvm,
1011+
&Profile::Opt,
1012+
benchmark_set.0,
1013+
)
1014+
.await
1015+
.unwrap();
1016+
1017+
let job = db
1018+
.dequeue_benchmark_job(collector_name, &target, &benchmark_set)
9911019
.await
1020+
.unwrap()
9921021
.unwrap();
9931022

1023+
assert_eq!(job.request_tag(), benchmark_request.tag().unwrap());
1024+
1025+
/* Mark the job as complete */
1026+
db.mark_benchmark_job_as_completed(job.id(), &BenchmarkJobConclusion::Success)
1027+
.await
1028+
.unwrap();
1029+
1030+
// record a couple of errors against the tag
1031+
let artifact_id = db.artifact_id(&ArtifactId::Tag(tag.to_string())).await;
1032+
1033+
db.record_error(artifact_id, "example-1", "This is an error")
1034+
.await;
1035+
db.record_error(artifact_id, "example-2", "This is another error")
1036+
.await;
1037+
1038+
db.mark_benchmark_request_as_completed(tag).await.unwrap();
1039+
1040+
let status_page_data = db.get_status_page_data().await.unwrap();
1041+
1042+
dbg!("{:?}", status_page_data);
1043+
9941044
Ok(ctx)
9951045
})
9961046
.await;

database/src/pool/postgres.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ where
19601960
let in_progress_requests_query = format!(
19611961
"
19621962
SELECT {BENCHMARK_REQUEST_COLUMNS}
1963-
FROM benchmark_requests
1963+
FROM benchmark_request
19641964
WHERE status = '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}'
19651965
"
19661966
);
@@ -2014,7 +2014,7 @@ where
20142014
)
20152015
SELECT
20162016
completed.*,
2017-
stats.*,
2017+
stats.duration::TEXT,
20182018
errors.errors AS errors
20192019
FROM
20202020
completed
@@ -2031,15 +2031,15 @@ where
20312031
.map(row_to_benchmark_request)
20322032
.collect();
20332033

2034-
let completed_requests: Vec<(BenchmarkRequest, u64, Vec<String>)> = self
2034+
let completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)> = self
20352035
.conn()
20362036
.query(&completed_requests_query, &[])
20372037
.await?
20382038
.iter()
20392039
.map(|it| {
20402040
(
20412041
row_to_benchmark_request(it),
2042-
it.get::<_, i64>(9) as u64,
2042+
it.get::<_, String>(9),
20432043
it.get::<_, Vec<String>>(10),
20442044
)
20452045
})
@@ -2050,6 +2050,8 @@ where
20502050
.map(|it| it.tag().unwrap())
20512051
.collect();
20522052

2053+
let in_progress_tags: String = in_progress_tags.join(",");
2054+
20532055
// We don't do a status check on the jobs as we want to return all jobs,
20542056
// irrespective of status, that are attached to an inprogress
20552057
// benchmark_request
@@ -2070,7 +2072,7 @@ where
20702072
completed_at,
20712073
retry
20722074
FROM
2073-
job_queue WHERE job_queue.tag IN ($1);",
2075+
job_queue WHERE job_queue.request_tag IN ($1);",
20742076
&[&in_progress_tags],
20752077
)
20762078
.await?;

0 commit comments

Comments
 (0)