@@ -2,7 +2,8 @@ use crate::selector::CompileTestCase;
2
2
use crate :: {
3
3
ArtifactCollection , ArtifactId , ArtifactIdNumber , BenchmarkJob , BenchmarkJobConclusion ,
4
4
BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkRequestWithErrors ,
5
- BenchmarkSet , CodegenBackend , CollectorConfig , CompileBenchmark , Target ,
5
+ BenchmarkSet , CodegenBackend , CollectorConfig , CompileBenchmark , PendingBenchmarkRequests ,
6
+ Target ,
6
7
} ;
7
8
use crate :: { CollectionId , Index , Profile , QueuedCommit , Scenario , Step } ;
8
9
use chrono:: { DateTime , Utc } ;
@@ -189,7 +190,8 @@ pub trait Connection: Send + Sync {
189
190
async fn purge_artifact ( & self , aid : & ArtifactId ) ;
190
191
191
192
/// Add an item to the `benchmark_requests`, if the `benchmark_request`
192
- /// exists an Error will be returned
193
+ /// exists an Error will be returned.
194
+ /// We require the caller to pass an index, to ensure that it is always kept up-to-date.
193
195
async fn insert_benchmark_request (
194
196
& self ,
195
197
benchmark_request : & BenchmarkRequest ,
@@ -200,7 +202,9 @@ pub trait Connection: Send + Sync {
200
202
201
203
/// Load all pending benchmark requests, i.e. those that have artifacts ready, but haven't
202
204
/// been completed yet. Pending statuses are `ArtifactsReady` and `InProgress`.
203
- async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < Vec < BenchmarkRequest > > ;
205
+ /// Also returns their parents, so that we can quickly check which requests are ready for being
206
+ /// enqueued.
207
+ async fn load_pending_benchmark_requests ( & self ) -> anyhow:: Result < PendingBenchmarkRequests > ;
204
208
205
209
/// Update the status of a `benchmark_request` with the given `tag`.
206
210
/// If no such request exists in the DB, returns an error.
@@ -426,9 +430,9 @@ mod tests {
426
430
use crate :: tests:: run_postgres_test;
427
431
use crate :: { tests:: run_db_test, BenchmarkRequestType , Commit , CommitType , Date } ;
428
432
use chrono:: Utc ;
433
+ use std:: collections:: BTreeSet ;
429
434
use std:: str:: FromStr ;
430
435
431
- /// Create a Commit
432
436
fn create_commit ( commit_sha : & str , time : chrono:: DateTime < Utc > , r#type : CommitType ) -> Commit {
433
437
Commit {
434
438
sha : commit_sha. into ( ) ,
@@ -437,43 +441,6 @@ mod tests {
437
441
}
438
442
}
439
443
440
- async fn complete_request (
441
- db : & dyn Connection ,
442
- request_tag : & str ,
443
- collector_name : & str ,
444
- benchmark_set : u32 ,
445
- target : Target ,
446
- ) {
447
- /* Create job for the request */
448
- db. enqueue_benchmark_job (
449
- request_tag,
450
- target,
451
- CodegenBackend :: Llvm ,
452
- Profile :: Opt ,
453
- benchmark_set,
454
- )
455
- . await
456
- . unwrap ( ) ;
457
-
458
- let ( job, _) = db
459
- . dequeue_benchmark_job ( collector_name, target, BenchmarkSet ( benchmark_set) )
460
- . await
461
- . unwrap ( )
462
- . unwrap ( ) ;
463
-
464
- assert_eq ! ( job. request_tag( ) , request_tag) ;
465
-
466
- /* Mark the job as complete */
467
- db. mark_benchmark_job_as_completed ( job. id ( ) , BenchmarkJobConclusion :: Success )
468
- . await
469
- . unwrap ( ) ;
470
-
471
- assert ! ( db
472
- . maybe_mark_benchmark_request_as_completed( request_tag)
473
- . await
474
- . unwrap( ) ) ;
475
- }
476
-
477
444
#[ tokio:: test]
478
445
async fn pstat_returns_empty_vector_when_empty ( ) {
479
446
run_db_test ( |ctx| async {
@@ -559,37 +526,25 @@ mod tests {
559
526
async fn multiple_non_completed_try_requests ( ) {
560
527
run_postgres_test ( |ctx| async {
561
528
let db = ctx. db ( ) ;
562
- let target = Target :: X86_64UnknownLinuxGnu ;
563
- let collector_name = "collector-1" ;
564
- let benchmark_set = 1 ;
565
-
566
- db. add_collector_config ( collector_name, target, benchmark_set, true )
567
- . await
568
- . unwrap ( ) ;
569
529
570
- // Complete parent
571
- let parent = BenchmarkRequest :: create_release ( "sha-parent-1" , Utc :: now ( ) ) ;
572
- // Complete
573
- let req_a = BenchmarkRequest :: create_try_without_artifacts ( 42 , "" , "" ) ;
574
- // WaitingForArtifacts
575
- let req_b = BenchmarkRequest :: create_try_without_artifacts ( 42 , "" , "" ) ;
576
- let req_c = BenchmarkRequest :: create_try_without_artifacts ( 42 , "" , "" ) ;
577
-
578
- db. insert_benchmark_request ( & parent) . await . unwrap ( ) ;
579
- db. insert_benchmark_request ( & req_a) . await . unwrap ( ) ;
580
- db. attach_shas_to_try_benchmark_request ( 42 , "sha1" , "sha-parent-1" , Utc :: now ( ) )
530
+ // Insert a try build
531
+ ctx. insert_try_request ( 42 ) . await ;
532
+ db. attach_shas_to_try_benchmark_request ( 42 , "sha-1" , "sha-parent-1" , Utc :: now ( ) )
581
533
. await
582
534
. unwrap ( ) ;
583
535
584
- complete_request ( db , "sha-parent-1" , collector_name , benchmark_set , target ) . await ;
585
- complete_request ( db , "sha1" , collector_name , benchmark_set , target ) . await ;
536
+ // Then finish it
537
+ ctx . complete_request ( "sha-1" ) . await ;
586
538
587
- // This should be fine, req_a was completed
588
- db. insert_benchmark_request ( & req_b) . await . unwrap ( ) ;
589
- // This should fail, we can't have two queued requests at once
590
- db. insert_benchmark_request ( & req_c) . await . expect_err (
591
- "It was possible to record two try benchmark requests without artifacts" ,
592
- ) ;
539
+ // Insert a try build for the same PR again
540
+ // This should be fine, because the previous request was already completed
541
+ ctx. insert_try_request ( 42 ) . await ;
542
+ // But this should fail, as we can't have two queued requests at once
543
+ db. insert_benchmark_request ( & BenchmarkRequest :: create_try_without_artifacts (
544
+ 42 , "" , "" ,
545
+ ) )
546
+ . await
547
+ . expect_err ( "It was possible to record two try benchmark requests without artifacts" ) ;
593
548
594
549
Ok ( ctx)
595
550
} )
@@ -629,43 +584,48 @@ mod tests {
629
584
async fn load_pending_benchmark_requests ( ) {
630
585
run_postgres_test ( |ctx| async {
631
586
let db = ctx. db ( ) ;
632
- let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
633
- let target = Target :: X86_64UnknownLinuxGnu ;
634
- let collector_name = "collector-1" ;
635
- let benchmark_set = 1 ;
636
-
637
- db. add_collector_config ( collector_name, target, benchmark_set, true )
638
- . await
639
- . unwrap ( ) ;
640
587
641
588
// ArtifactsReady
642
- let req_a = BenchmarkRequest :: create_master ( "sha-1" , "parent-sha-1" , 42 , time ) ;
589
+ let req_a = ctx . insert_master_request ( "sha-1" , "parent-sha-1" , 42 ) . await ;
643
590
// ArtifactsReady
644
- let req_b = BenchmarkRequest :: create_release ( "1.80.0" , time ) ;
591
+ let req_b = ctx . insert_release_request ( "1.80.0" ) . await ;
645
592
// WaitingForArtifacts
646
- let req_c = BenchmarkRequest :: create_try_without_artifacts ( 50 , "" , "" ) ;
593
+ ctx . insert_try_request ( 50 ) . await ;
647
594
// InProgress
648
- let req_d = BenchmarkRequest :: create_master ( "sha-2" , "parent-sha-2" , 51 , time ) ;
595
+ let req_d = ctx . insert_master_request ( "sha-2" , "parent-sha-2" , 51 ) . await ;
649
596
// Completed
650
- let req_e = BenchmarkRequest :: create_release ( "1.79.0" , time ) ;
597
+ ctx . insert_release_request ( "1.79.0" ) . await ;
651
598
652
- for & req in & [ & req_a, & req_b, & req_c, & req_d, & req_e] {
653
- db. insert_benchmark_request ( req) . await . unwrap ( ) ;
654
- }
655
-
656
- complete_request ( db, "1.79.0" , collector_name, benchmark_set, target) . await ;
599
+ ctx. complete_request ( "1.79.0" ) . await ;
600
+ ctx. insert_master_request ( "parent-sha-1" , "grandparent-sha-0" , 100 )
601
+ . await ;
602
+ ctx. complete_request ( "parent-sha-1" ) . await ;
603
+ ctx. insert_master_request ( "parent-sha-2" , "grandparent-sha-1" , 101 )
604
+ . await ;
605
+ ctx. complete_request ( "parent-sha-2" ) . await ;
657
606
658
607
db. update_benchmark_request_status ( "sha-2" , BenchmarkRequestStatus :: InProgress )
659
608
. await
660
609
. unwrap ( ) ;
661
610
662
- let requests = db. load_pending_benchmark_requests ( ) . await . unwrap ( ) ;
611
+ let pending = db. load_pending_benchmark_requests ( ) . await . unwrap ( ) ;
612
+ let requests = pending. requests ;
663
613
664
614
assert_eq ! ( requests. len( ) , 3 ) ;
665
615
for req in & [ req_a, req_b, req_d] {
666
616
assert ! ( requests. iter( ) . any( |r| r. tag( ) == req. tag( ) ) ) ;
667
617
}
668
618
619
+ assert_eq ! (
620
+ pending
621
+ . completed_parent_tags
622
+ . into_iter( )
623
+ . collect:: <BTreeSet <_>>( )
624
+ . into_iter( )
625
+ . collect:: <Vec <_>>( ) ,
626
+ vec![ "parent-sha-1" . to_string( ) , "parent-sha-2" . to_string( ) ]
627
+ ) ;
628
+
669
629
Ok ( ctx)
670
630
} )
671
631
. await ;
@@ -687,6 +647,7 @@ mod tests {
687
647
. load_pending_benchmark_requests ( )
688
648
. await
689
649
. unwrap ( )
650
+ . requests
690
651
. into_iter ( )
691
652
. next ( )
692
653
. unwrap ( ) ;
0 commit comments