|
1 | 1 | use crate::{ |
2 | | - ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, CodegenBackend, |
3 | | - CompileBenchmark, Target, |
| 2 | + ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, BenchmarkRequestStatus, |
| 3 | + CodegenBackend, CompileBenchmark, Target, |
4 | 4 | }; |
5 | 5 | use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step}; |
6 | 6 | use chrono::{DateTime, Utc}; |
@@ -183,6 +183,20 @@ pub trait Connection: Send + Sync { |
183 | 183 | /// Add an item to the `benchmark_requests`, if the `benchmark_request` |
184 | 184 | /// exists it will be ignored |
185 | 185 | async fn insert_benchmark_request(&self, benchmark_request: &BenchmarkRequest); |
| 186 | + |
| 187 | + /// Gets the benchmark requests matching the status. Optionally provide the |
| 188 | + /// number of days from whence to search from |
| 189 | + async fn get_benchmark_requests_by_status( |
| 190 | + &self, |
| 191 | + statuses: &[BenchmarkRequestStatus], |
| 192 | + ) -> anyhow::Result<Vec<BenchmarkRequest>>; |
| 193 | + |
| 194 | + /// Update the status of a `benchmark_request` |
| 195 | + async fn update_benchmark_request_status( |
| 196 | + &mut self, |
| 197 | + benchmark_request: &BenchmarkRequest, |
| 198 | + benchmark_request_status: BenchmarkRequestStatus, |
| 199 | + ) -> anyhow::Result<()>; |
186 | 200 | } |
187 | 201 |
|
188 | 202 | #[async_trait::async_trait] |
@@ -396,7 +410,7 @@ mod tests { |
396 | 410 |
|
397 | 411 | let try_benchmark_request = BenchmarkRequest::create_try( |
398 | 412 | "b-sha-2", |
399 | | - "parent-sha-2", |
| 413 | + Some("parent-sha-2"), |
400 | 414 | 32, |
401 | 415 | time, |
402 | 416 | BenchmarkRequestStatus::ArtifactsReady, |
@@ -424,4 +438,100 @@ mod tests { |
424 | 438 | }) |
425 | 439 | .await; |
426 | 440 | } |
| 441 | + |
| 442 | + #[tokio::test] |
| 443 | + async fn get_benchmark_requests_by_status() { |
| 444 | + // Ensure we get back the requests matching the status with no date |
| 445 | + // limit |
| 446 | + run_postgres_test(|ctx| async { |
| 447 | + let db = ctx.db_client(); |
| 448 | + let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap(); |
| 449 | + let master_benchmark_request = BenchmarkRequest::create_master( |
| 450 | + "a-sha-1", |
| 451 | + "parent-sha-1", |
| 452 | + 42, |
| 453 | + time, |
| 454 | + BenchmarkRequestStatus::ArtifactsReady, |
| 455 | + "llvm", |
| 456 | + "", |
| 457 | + ); |
| 458 | + |
| 459 | + let try_benchmark_request = BenchmarkRequest::create_try( |
| 460 | + "b-sha-2", |
| 461 | + Some("parent-sha-2"), |
| 462 | + 32, |
| 463 | + time, |
| 464 | + BenchmarkRequestStatus::Completed, |
| 465 | + "cranelift", |
| 466 | + "", |
| 467 | + ); |
| 468 | + |
| 469 | + let release_benchmark_request = BenchmarkRequest::create_release( |
| 470 | + "1.8.0", |
| 471 | + time, |
| 472 | + BenchmarkRequestStatus::ArtifactsReady, |
| 473 | + "cranelift,llvm", |
| 474 | + "", |
| 475 | + ); |
| 476 | + |
| 477 | + let db = db.connection().await; |
| 478 | + db.insert_benchmark_request(&master_benchmark_request).await; |
| 479 | + db.insert_benchmark_request(&try_benchmark_request).await; |
| 480 | + db.insert_benchmark_request(&release_benchmark_request) |
| 481 | + .await; |
| 482 | + |
| 483 | + let requests = db |
| 484 | + .get_benchmark_requests_by_status(&[BenchmarkRequestStatus::ArtifactsReady]) |
| 485 | + .await |
| 486 | + .unwrap(); |
| 487 | + |
| 488 | + assert_eq!(requests.len(), 2); |
| 489 | + assert_eq!(requests[0].status, BenchmarkRequestStatus::ArtifactsReady); |
| 490 | + assert_eq!(requests[1].status, BenchmarkRequestStatus::ArtifactsReady); |
| 491 | + |
| 492 | + Ok(ctx) |
| 493 | + }) |
| 494 | + .await; |
| 495 | + } |
| 496 | + |
| 497 | + #[tokio::test] |
| 498 | + async fn update_benchmark_request_status() { |
| 499 | + // Insert one item into the database, change the status and then |
| 500 | + // get the item back out again to ensure it has changed status |
| 501 | + run_postgres_test(|ctx| async { |
| 502 | + let db = ctx.db_client(); |
| 503 | + let time = chrono::DateTime::from_str("2021-09-01T00:00:00.000Z").unwrap(); |
| 504 | + let master_benchmark_request = BenchmarkRequest::create_master( |
| 505 | + "a-sha-1", |
| 506 | + "parent-sha-1", |
| 507 | + 42, |
| 508 | + time, |
| 509 | + BenchmarkRequestStatus::ArtifactsReady, |
| 510 | + "llvm", |
| 511 | + "", |
| 512 | + ); |
| 513 | + |
| 514 | + let mut db = db.connection().await; |
| 515 | + db.insert_benchmark_request(&master_benchmark_request).await; |
| 516 | + |
| 517 | + db.update_benchmark_request_status( |
| 518 | + &master_benchmark_request, |
| 519 | + BenchmarkRequestStatus::InProgress, |
| 520 | + ) |
| 521 | + .await |
| 522 | + .unwrap(); |
| 523 | + |
| 524 | + let requests = db |
| 525 | + .get_benchmark_requests_by_status(&[BenchmarkRequestStatus::InProgress]) |
| 526 | + .await |
| 527 | + .unwrap(); |
| 528 | + |
| 529 | + assert_eq!(requests.len(), 1); |
| 530 | + assert_eq!(requests[0].tag(), master_benchmark_request.tag()); |
| 531 | + assert_eq!(requests[0].status, BenchmarkRequestStatus::InProgress); |
| 532 | + |
| 533 | + Ok(ctx) |
| 534 | + }) |
| 535 | + .await; |
| 536 | + } |
427 | 537 | } |
0 commit comments