Skip to content

Commit 1aafc44

Browse files
committed
statisfied that ARRAY_AGG(...) can be used
1 parent 3f720df commit 1aafc44

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
@@ -1206,7 +1206,7 @@ impl CollectorConfig {
12061206
/// status page
12071207
#[derive(Debug, PartialEq)]
12081208
pub struct PartialStatusPageData {
1209-
pub completed_requests: Vec<(BenchmarkRequest, u64, Vec<String>)>,
1209+
pub completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)>,
12101210
pub in_progress_jobs: Vec<BenchmarkJob>,
12111211
pub in_progress_requests: Vec<BenchmarkRequest>,
12121212
}

database/src/pool.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,13 +976,63 @@ mod tests {
976976
.await;
977977
}
978978

979+
#[tokio::test]
979980
async fn get_status_page_data() {
980981
run_postgres_test(|ctx| async {
981982
let db = ctx.db_client().connection().await;
982-
db.add_collector_config("collector-1", &Target::X86_64UnknownLinuxGnu, 1, true)
983+
let benchmark_set = BenchmarkSet(0u32);
984+
let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap();
985+
let tag = "sha-1";
986+
let collector_name = "collector-1";
987+
let target = Target::X86_64UnknownLinuxGnu;
988+
989+
db.add_collector_config(collector_name, &target, benchmark_set.0, true)
990+
.await
991+
.unwrap();
992+
993+
let benchmark_request = BenchmarkRequest::create_release(tag, time);
994+
db.insert_benchmark_request(&benchmark_request)
995+
.await
996+
.unwrap();
997+
998+
/* Create job for the request */
999+
db.enqueue_benchmark_job(
1000+
benchmark_request.tag().unwrap(),
1001+
&target,
1002+
&CodegenBackend::Llvm,
1003+
&Profile::Opt,
1004+
benchmark_set.0,
1005+
)
1006+
.await
1007+
.unwrap();
1008+
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)
9831019
.await
9841020
.unwrap();
9851021

1022+
// record a couple of errors against the tag
1023+
let artifact_id = db.artifact_id(&ArtifactId::Tag(tag.to_string())).await;
1024+
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;
1029+
1030+
db.mark_benchmark_request_as_completed(tag).await.unwrap();
1031+
1032+
let status_page_data = db.get_status_page_data().await.unwrap();
1033+
1034+
dbg!("{:?}", status_page_data);
1035+
9861036
Ok(ctx)
9871037
})
9881038
.await;

database/src/pool/postgres.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ where
19181918
let in_progress_requests_query = format!(
19191919
"
19201920
SELECT {BENCHMARK_REQUEST_COLUMNS}
1921-
FROM benchmark_requests
1921+
FROM benchmark_request
19221922
WHERE status = '{BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR}'
19231923
"
19241924
);
@@ -1972,7 +1972,7 @@ where
19721972
)
19731973
SELECT
19741974
completed.*,
1975-
stats.*,
1975+
stats.duration::TEXT,
19761976
errors.errors AS errors
19771977
FROM
19781978
completed
@@ -1989,15 +1989,15 @@ where
19891989
.map(row_to_benchmark_request)
19901990
.collect();
19911991

1992-
let completed_requests: Vec<(BenchmarkRequest, u64, Vec<String>)> = self
1992+
let completed_requests: Vec<(BenchmarkRequest, String, Vec<String>)> = self
19931993
.conn()
19941994
.query(&completed_requests_query, &[])
19951995
.await?
19961996
.iter()
19971997
.map(|it| {
19981998
(
19991999
row_to_benchmark_request(it),
2000-
it.get::<_, i64>(9) as u64,
2000+
it.get::<_, String>(9),
20012001
it.get::<_, Vec<String>>(10),
20022002
)
20032003
})
@@ -2008,6 +2008,8 @@ where
20082008
.map(|it| it.tag().unwrap())
20092009
.collect();
20102010

2011+
let in_progress_tags: String = in_progress_tags.join(",");
2012+
20112013
// We don't do a status check on the jobs as we want to return all jobs,
20122014
// irrespective of status, that are attached to an inprogress
20132015
// benchmark_request
@@ -2028,7 +2030,7 @@ where
20282030
completed_at,
20292031
retry
20302032
FROM
2031-
job_queue WHERE job_queue.tag IN ($1);",
2033+
job_queue WHERE job_queue.request_tag IN ($1);",
20322034
&[&in_progress_tags],
20332035
)
20342036
.await?;

0 commit comments

Comments
 (0)