1
1
use crate :: selector:: CompileTestCase ;
2
2
use crate :: {
3
- ArtifactCollection , ArtifactId , ArtifactIdNumber , BenchmarkJob , BenchmarkRequest ,
4
- BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkSet , CodegenBackend , CollectorConfig ,
5
- CompileBenchmark , Target ,
3
+ ArtifactCollection , ArtifactId , ArtifactIdNumber , BenchmarkJob , BenchmarkJobConclusion ,
4
+ BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkSet , CodegenBackend ,
5
+ CollectorConfig , CompileBenchmark , Target ,
6
6
} ;
7
7
use crate :: { CollectionId , Index , Profile , QueuedCommit , Scenario , Step } ;
8
8
use chrono:: { DateTime , Utc } ;
@@ -246,13 +246,25 @@ pub trait Connection: Send + Sync {
246
246
/// Get the confiuguration for a collector by the name of the collector
247
247
async fn get_collector_config ( & self , collector_name : & str ) -> anyhow:: Result < CollectorConfig > ;
248
248
249
- /// Get the confiuguration for a collector by the name of the collector
249
+ /// Dequeue benchmark job
250
250
async fn dequeue_benchmark_job (
251
251
& self ,
252
252
collector_name : & str ,
253
253
target : & Target ,
254
254
benchmark_set : & BenchmarkSet ,
255
255
) -> anyhow:: Result < Option < BenchmarkJob > > ;
256
+
257
+ /// Try and mark the benchmark_request as completed. Will return `true` if
258
+ /// it has been marked as completed else `false` meaning there was no change
259
+ async fn mark_benchmark_request_as_completed ( & self , tag : & str ) -> anyhow:: Result < bool > ;
260
+
261
+ /// Mark the job as completed. Sets the status to 'failed' or 'success'
262
+ /// depending on the enum's completed state being a success
263
+ async fn mark_benchmark_job_as_completed (
264
+ & self ,
265
+ id : u32 ,
266
+ benchmark_job_conculsion : & BenchmarkJobConclusion ,
267
+ ) -> anyhow:: Result < ( ) > ;
256
268
}
257
269
258
270
#[ async_trait:: async_trait]
@@ -388,6 +400,45 @@ mod tests {
388
400
}
389
401
}
390
402
403
+ async fn complete_request (
404
+ db : & dyn Connection ,
405
+ request_tag : & str ,
406
+ collector_name : & str ,
407
+ benchmark_set : u32 ,
408
+ target : & Target ,
409
+ ) {
410
+ /* Create job for the request */
411
+ db. enqueue_benchmark_job (
412
+ request_tag,
413
+ & target,
414
+ & CodegenBackend :: Llvm ,
415
+ & Profile :: Opt ,
416
+ benchmark_set,
417
+ )
418
+ . await
419
+ . unwrap ( ) ;
420
+
421
+ let job = db
422
+ . dequeue_benchmark_job ( collector_name, & target, & BenchmarkSet ( benchmark_set) )
423
+ . await
424
+ . unwrap ( )
425
+ . unwrap ( ) ;
426
+
427
+ assert_eq ! ( job. request_tag( ) , request_tag) ;
428
+
429
+ /* Mark the job as complete */
430
+ db. mark_benchmark_job_as_completed ( job. id ( ) , & BenchmarkJobConclusion :: Success )
431
+ . await
432
+ . unwrap ( ) ;
433
+
434
+ assert_eq ! (
435
+ db. mark_benchmark_request_as_completed( request_tag)
436
+ . await
437
+ . unwrap( ) ,
438
+ true
439
+ ) ;
440
+ }
441
+
391
442
#[ tokio:: test]
392
443
async fn pstat_returns_empty_vector_when_empty ( ) {
393
444
run_db_test ( |ctx| async {
@@ -475,28 +526,31 @@ mod tests {
475
526
#[ tokio:: test]
476
527
async fn multiple_non_completed_try_requests ( ) {
477
528
run_postgres_test ( |ctx| async {
478
- let db = ctx. db_client ( ) ;
479
- let db = db. connection ( ) . await ;
529
+ let db = ctx. db_client ( ) . connection ( ) . await ;
530
+ let target = & Target :: X86_64UnknownLinuxGnu ;
531
+ let collector_name = "collector-1" ;
532
+ let benchmark_set = 1 ;
480
533
481
- // Completed
534
+ db. add_collector_config ( collector_name, & target, benchmark_set, true )
535
+ . await
536
+ . unwrap ( ) ;
537
+
538
+ // Complete parent
539
+ let parent = BenchmarkRequest :: create_release ( "sha-parent-1" , Utc :: now ( ) ) ;
540
+ // Complete
482
541
let req_a = BenchmarkRequest :: create_try_without_artifacts ( 42 , Utc :: now ( ) , "" , "" ) ;
483
542
// WaitingForArtifacts
484
543
let req_b = BenchmarkRequest :: create_try_without_artifacts ( 42 , Utc :: now ( ) , "" , "" ) ;
485
544
let req_c = BenchmarkRequest :: create_try_without_artifacts ( 42 , Utc :: now ( ) , "" , "" ) ;
486
545
546
+ db. insert_benchmark_request ( & parent) . await . unwrap ( ) ;
487
547
db. insert_benchmark_request ( & req_a) . await . unwrap ( ) ;
488
548
db. attach_shas_to_try_benchmark_request ( 42 , "sha1" , "sha-parent-1" )
489
549
. await
490
550
. unwrap ( ) ;
491
551
492
- db. update_benchmark_request_status (
493
- "sha1" ,
494
- BenchmarkRequestStatus :: Completed {
495
- completed_at : Utc :: now ( ) ,
496
- } ,
497
- )
498
- . await
499
- . unwrap ( ) ;
552
+ complete_request ( & * db, "sha-parent-1" , collector_name, benchmark_set, & target) . await ;
553
+ complete_request ( & * db, "sha1" , collector_name, benchmark_set, & target) . await ;
500
554
501
555
// This should be fine, req_a was completed
502
556
db. insert_benchmark_request ( & req_b) . await . unwrap ( ) ;
@@ -543,8 +597,15 @@ mod tests {
543
597
#[ tokio:: test]
544
598
async fn load_pending_benchmark_requests ( ) {
545
599
run_postgres_test ( |ctx| async {
546
- let db = ctx. db_client ( ) ;
600
+ let db = ctx. db_client ( ) . connection ( ) . await ;
547
601
let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
602
+ let target = & Target :: X86_64UnknownLinuxGnu ;
603
+ let collector_name = "collector-1" ;
604
+ let benchmark_set = 1 ;
605
+
606
+ db. add_collector_config ( collector_name, & target, benchmark_set, true )
607
+ . await
608
+ . unwrap ( ) ;
548
609
549
610
// ArtifactsReady
550
611
let req_a = BenchmarkRequest :: create_master ( "sha-1" , "parent-sha-1" , 42 , time) ;
@@ -555,24 +616,17 @@ mod tests {
555
616
// InProgress
556
617
let req_d = BenchmarkRequest :: create_master ( "sha-2" , "parent-sha-2" , 51 , time) ;
557
618
// Completed
558
- let req_e = BenchmarkRequest :: create_master ( "sha-3" , "parent-sha-3" , 52 , time) ;
619
+ let req_e = BenchmarkRequest :: create_release ( "1.79.0" , time) ;
559
620
560
- let db = db. connection ( ) . await ;
561
621
for & req in & [ & req_a, & req_b, & req_c, & req_d, & req_e] {
562
622
db. insert_benchmark_request ( req) . await . unwrap ( ) ;
563
623
}
564
624
625
+ complete_request ( & * db, "1.79.0" , collector_name, benchmark_set, & target) . await ;
626
+
565
627
db. update_benchmark_request_status ( "sha-2" , BenchmarkRequestStatus :: InProgress )
566
628
. await
567
629
. unwrap ( ) ;
568
- db. update_benchmark_request_status (
569
- "sha-3" ,
570
- BenchmarkRequestStatus :: Completed {
571
- completed_at : Utc :: now ( ) ,
572
- } ,
573
- )
574
- . await
575
- . unwrap ( ) ;
576
630
577
631
let requests = db. load_pending_benchmark_requests ( ) . await . unwrap ( ) ;
578
632
@@ -837,4 +891,87 @@ mod tests {
837
891
} )
838
892
. await ;
839
893
}
894
+
895
+ #[ tokio:: test]
896
+ async fn mark_request_as_complete_empty ( ) {
897
+ run_postgres_test ( |ctx| async {
898
+ let db = ctx. db_client ( ) . connection ( ) . await ;
899
+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
900
+
901
+ let insert_result = db
902
+ . add_collector_config ( "collector-1" , & Target :: X86_64UnknownLinuxGnu , 1 , true )
903
+ . await ;
904
+ assert ! ( insert_result. is_ok( ) ) ;
905
+
906
+ let benchmark_request =
907
+ BenchmarkRequest :: create_master ( "sha-1" , "parent-sha-1" , 42 , time) ;
908
+ db. insert_benchmark_request ( & benchmark_request)
909
+ . await
910
+ . unwrap ( ) ;
911
+ assert_eq ! (
912
+ db. mark_benchmark_request_as_completed( "sha-1" )
913
+ . await
914
+ . unwrap( ) ,
915
+ true
916
+ ) ;
917
+ Ok ( ctx)
918
+ } )
919
+ . await ;
920
+ }
921
+
922
+ #[ tokio:: test]
923
+ async fn mark_request_as_complete ( ) {
924
+ run_postgres_test ( |ctx| async {
925
+ let db = ctx. db_client ( ) . connection ( ) . await ;
926
+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
927
+ let benchmark_set = BenchmarkSet ( 0u32 ) ;
928
+ let tag = "sha-1" ;
929
+ let collector_name = "collector-1" ;
930
+ let target = Target :: X86_64UnknownLinuxGnu ;
931
+
932
+ let insert_result = db
933
+ . add_collector_config ( collector_name, & target, 1 , true )
934
+ . await ;
935
+ assert ! ( insert_result. is_ok( ) ) ;
936
+
937
+ /* Create the request */
938
+ let benchmark_request = BenchmarkRequest :: create_release ( tag, time) ;
939
+ db. insert_benchmark_request ( & benchmark_request)
940
+ . await
941
+ . unwrap ( ) ;
942
+
943
+ /* Create job for the request */
944
+ db. enqueue_benchmark_job (
945
+ benchmark_request. tag ( ) . unwrap ( ) ,
946
+ & target,
947
+ & CodegenBackend :: Llvm ,
948
+ & Profile :: Opt ,
949
+ benchmark_set. 0 ,
950
+ )
951
+ . await
952
+ . unwrap ( ) ;
953
+
954
+ let job = db
955
+ . dequeue_benchmark_job ( collector_name, & target, & benchmark_set)
956
+ . await
957
+ . unwrap ( )
958
+ . unwrap ( ) ;
959
+
960
+ assert_eq ! ( job. request_tag( ) , benchmark_request. tag( ) . unwrap( ) ) ;
961
+
962
+ /* Mark the job as complete */
963
+ db. mark_benchmark_job_as_completed ( job. id ( ) , & BenchmarkJobConclusion :: Success )
964
+ . await
965
+ . unwrap ( ) ;
966
+
967
+ db. mark_benchmark_request_as_completed ( tag) . await . unwrap ( ) ;
968
+
969
+ let completed = db. load_benchmark_request_index ( ) . await . unwrap ( ) ;
970
+
971
+ assert ! ( completed. contains_tag( "sha-1" ) ) ;
972
+
973
+ Ok ( ctx)
974
+ } )
975
+ . await ;
976
+ }
840
977
}
0 commit comments