|
1 | 1 | use crate::selector::CompileTestCase;
|
2 | 2 | use crate::{
|
3 |
| - ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, CodegenBackend, |
4 |
| - CompileBenchmark, Target, |
| 3 | + ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, BenchmarkRequestStatus, |
| 4 | + CodegenBackend, CompileBenchmark, Target, |
5 | 5 | };
|
6 | 6 | use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
|
7 | 7 | use chrono::{DateTime, Utc};
|
@@ -195,6 +195,20 @@ pub trait Connection: Send + Sync {
|
195 | 195 | &self,
|
196 | 196 | artifact_row_id: &ArtifactIdNumber,
|
197 | 197 | ) -> anyhow::Result<HashSet<CompileTestCase>>;
|
| 198 | + |
| 199 | + /// Gets the benchmark requests matching the status. Optionally provide the |
| 200 | + /// number of days from whence to search from |
| 201 | + async fn get_benchmark_requests_by_status( |
| 202 | + &self, |
| 203 | + statuses: &[BenchmarkRequestStatus], |
| 204 | + ) -> anyhow::Result<Vec<BenchmarkRequest>>; |
| 205 | + |
| 206 | + /// Update the status of a `benchmark_request` |
| 207 | + async fn update_benchmark_request_status( |
| 208 | + &mut self, |
| 209 | + benchmark_request: &BenchmarkRequest, |
| 210 | + benchmark_request_status: BenchmarkRequestStatus, |
| 211 | + ) -> anyhow::Result<()>; |
198 | 212 | }
|
199 | 213 |
|
200 | 214 | #[async_trait::async_trait]
|
@@ -406,7 +420,7 @@ mod tests {
|
406 | 420 |
|
407 | 421 | let try_benchmark_request = BenchmarkRequest::create_try(
|
408 | 422 | "b-sha-2",
|
409 |
| - "parent-sha-2", |
| 423 | + Some("parent-sha-2"), |
410 | 424 | 32,
|
411 | 425 | time,
|
412 | 426 | BenchmarkRequestStatus::ArtifactsReady,
|
@@ -494,4 +508,100 @@ mod tests {
|
494 | 508 | })
|
495 | 509 | .await;
|
496 | 510 | }
|
| 511 | + |
| 512 | + #[tokio::test] |
| 513 | + async fn get_benchmark_requests_by_status() { |
| 514 | + // Ensure we get back the requests matching the status with no date |
| 515 | + // limit |
| 516 | + run_postgres_test(|ctx| async { |
| 517 | + let db = ctx.db_client(); |
| 518 | + let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap(); |
| 519 | + let master_benchmark_request = BenchmarkRequest::create_master( |
| 520 | + "a-sha-1", |
| 521 | + "parent-sha-1", |
| 522 | + 42, |
| 523 | + time, |
| 524 | + BenchmarkRequestStatus::ArtifactsReady, |
| 525 | + "llvm", |
| 526 | + "", |
| 527 | + ); |
| 528 | + |
| 529 | + let try_benchmark_request = BenchmarkRequest::create_try( |
| 530 | + "b-sha-2", |
| 531 | + Some("parent-sha-2"), |
| 532 | + 32, |
| 533 | + time, |
| 534 | + BenchmarkRequestStatus::Completed, |
| 535 | + "cranelift", |
| 536 | + "", |
| 537 | + ); |
| 538 | + |
| 539 | + let release_benchmark_request = BenchmarkRequest::create_release( |
| 540 | + "1.8.0", |
| 541 | + time, |
| 542 | + BenchmarkRequestStatus::ArtifactsReady, |
| 543 | + "cranelift,llvm", |
| 544 | + "", |
| 545 | + ); |
| 546 | + |
| 547 | + let db = db.connection().await; |
| 548 | + db.insert_benchmark_request(&master_benchmark_request).await; |
| 549 | + db.insert_benchmark_request(&try_benchmark_request).await; |
| 550 | + db.insert_benchmark_request(&release_benchmark_request) |
| 551 | + .await; |
| 552 | + |
| 553 | + let requests = db |
| 554 | + .get_benchmark_requests_by_status(&[BenchmarkRequestStatus::ArtifactsReady]) |
| 555 | + .await |
| 556 | + .unwrap(); |
| 557 | + |
| 558 | + assert_eq!(requests.len(), 2); |
| 559 | + assert_eq!(requests[0].status, BenchmarkRequestStatus::ArtifactsReady); |
| 560 | + assert_eq!(requests[1].status, BenchmarkRequestStatus::ArtifactsReady); |
| 561 | + |
| 562 | + Ok(ctx) |
| 563 | + }) |
| 564 | + .await; |
| 565 | + } |
| 566 | + |
| 567 | + #[tokio::test] |
| 568 | + async fn update_benchmark_request_status() { |
| 569 | + // Insert one item into the database, change the status and then |
| 570 | + // get the item back out again to ensure it has changed status |
| 571 | + run_postgres_test(|ctx| async { |
| 572 | + let db = ctx.db_client(); |
| 573 | + let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap(); |
| 574 | + let master_benchmark_request = BenchmarkRequest::create_master( |
| 575 | + "a-sha-1", |
| 576 | + "parent-sha-1", |
| 577 | + 42, |
| 578 | + time, |
| 579 | + BenchmarkRequestStatus::ArtifactsReady, |
| 580 | + "llvm", |
| 581 | + "", |
| 582 | + ); |
| 583 | + |
| 584 | + let mut db = db.connection().await; |
| 585 | + db.insert_benchmark_request(&master_benchmark_request).await; |
| 586 | + |
| 587 | + db.update_benchmark_request_status( |
| 588 | + &master_benchmark_request, |
| 589 | + BenchmarkRequestStatus::InProgress, |
| 590 | + ) |
| 591 | + .await |
| 592 | + .unwrap(); |
| 593 | + |
| 594 | + let requests = db |
| 595 | + .get_benchmark_requests_by_status(&[BenchmarkRequestStatus::InProgress]) |
| 596 | + .await |
| 597 | + .unwrap(); |
| 598 | + |
| 599 | + assert_eq!(requests.len(), 1); |
| 600 | + assert_eq!(requests[0].tag(), master_benchmark_request.tag()); |
| 601 | + assert_eq!(requests[0].status, BenchmarkRequestStatus::InProgress); |
| 602 | + |
| 603 | + Ok(ctx) |
| 604 | + }) |
| 605 | + .await; |
| 606 | + } |
497 | 607 | }
|
0 commit comments