@@ -389,6 +389,7 @@ mod tests {
389
389
use super :: * ;
390
390
use crate :: metric:: Metric ;
391
391
use crate :: tests:: run_postgres_test;
392
+ use crate :: BenchmarkJobStatus ;
392
393
use crate :: { tests:: run_db_test, BenchmarkRequestType , Commit , CommitType , Date } ;
393
394
use chrono:: Utc ;
394
395
use std:: str:: FromStr ;
@@ -983,6 +984,7 @@ mod tests {
983
984
let benchmark_set = BenchmarkSet ( 0u32 ) ;
984
985
let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
985
986
let tag = "sha-1" ;
987
+ let tag_two = "sha-2" ;
986
988
let collector_name = "collector-1" ;
987
989
let target = Target :: X86_64UnknownLinuxGnu ;
988
990
@@ -995,43 +997,117 @@ mod tests {
995
997
. await
996
998
. unwrap ( ) ;
997
999
998
- /* Create job for the request */
1000
+ complete_request ( & * db, tag, collector_name, benchmark_set. 0 , & target) . await ;
1001
+ // record a couple of errors against the tag
1002
+ let artifact_id = db. artifact_id ( & ArtifactId :: Tag ( tag. to_string ( ) ) ) . await ;
1003
+
1004
+ db. record_error ( artifact_id, "example-1" , "This is an error" )
1005
+ . await ;
1006
+ db. record_error ( artifact_id, "example-2" , "This is another error" )
1007
+ . await ;
1008
+
1009
+ let benchmark_request_two = BenchmarkRequest :: create_release ( tag_two, time) ;
1010
+ db. insert_benchmark_request ( & benchmark_request_two)
1011
+ . await
1012
+ . unwrap ( ) ;
1013
+
999
1014
db. enqueue_benchmark_job (
1000
- benchmark_request . tag ( ) . unwrap ( ) ,
1015
+ benchmark_request_two . tag ( ) . unwrap ( ) ,
1001
1016
& target,
1002
1017
& CodegenBackend :: Llvm ,
1003
1018
& Profile :: Opt ,
1004
1019
benchmark_set. 0 ,
1005
1020
)
1006
1021
. await
1007
1022
. unwrap ( ) ;
1023
+ db. enqueue_benchmark_job (
1024
+ benchmark_request_two. tag ( ) . unwrap ( ) ,
1025
+ & target,
1026
+ & CodegenBackend :: Llvm ,
1027
+ & Profile :: Debug ,
1028
+ benchmark_set. 0 ,
1029
+ )
1030
+ . await
1031
+ . unwrap ( ) ;
1008
1032
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 )
1019
- . await
1020
- . unwrap ( ) ;
1033
+ db. update_benchmark_request_status (
1034
+ benchmark_request_two. tag ( ) . unwrap ( ) ,
1035
+ BenchmarkRequestStatus :: InProgress ,
1036
+ )
1037
+ . await
1038
+ . unwrap ( ) ;
1021
1039
1022
- // record a couple of errors against the tag
1023
- let artifact_id = db. artifact_id ( & ArtifactId :: Tag ( tag. to_string ( ) ) ) . await ;
1040
+ let status_page_data = db. get_status_page_data ( ) . await . unwrap ( ) ;
1024
1041
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 ;
1042
+ assert ! ( status_page_data. completed_requests. len( ) == 1 ) ;
1043
+ assert_eq ! ( status_page_data. completed_requests[ 0 ] . 0 . tag( ) . unwrap( ) , tag) ;
1044
+ assert ! ( matches!(
1045
+ status_page_data. completed_requests[ 0 ] . 0 . status( ) ,
1046
+ BenchmarkRequestStatus :: Completed { .. }
1047
+ ) ) ;
1048
+ // can't really test duration
1049
+ // ensure errors are correct
1050
+ assert_eq ! (
1051
+ status_page_data. completed_requests[ 0 ] . 2 [ 0 ] ,
1052
+ "This is an error" . to_string( )
1053
+ ) ;
1054
+ assert_eq ! (
1055
+ status_page_data. completed_requests[ 0 ] . 2 [ 1 ] ,
1056
+ "This is another error" . to_string( )
1057
+ ) ;
1029
1058
1030
- db. mark_benchmark_request_as_completed ( tag) . await . unwrap ( ) ;
1059
+ assert ! ( status_page_data. in_progress. len( ) == 1 ) ;
1060
+ // we should have 2 jobs
1061
+ assert ! ( status_page_data. in_progress[ 0 ] . 1 . len( ) == 2 ) ;
1062
+ // the request should be in progress
1063
+ assert ! ( matches!(
1064
+ status_page_data. in_progress[ 0 ] . 0 . status( ) ,
1065
+ BenchmarkRequestStatus :: InProgress
1066
+ ) ) ;
1031
1067
1032
- let status_page_data = db. get_status_page_data ( ) . await . unwrap ( ) ;
1068
+ // Test the first job
1069
+ assert ! ( matches!(
1070
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . target( ) ,
1071
+ Target :: X86_64UnknownLinuxGnu
1072
+ ) ) ;
1073
+ assert ! ( matches!(
1074
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . status( ) ,
1075
+ BenchmarkJobStatus :: Queued
1076
+ ) ) ;
1077
+ assert ! ( matches!(
1078
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . backend( ) ,
1079
+ CodegenBackend :: Llvm
1080
+ ) ) ;
1081
+ assert ! ( matches!(
1082
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . profile( ) ,
1083
+ Profile :: Opt
1084
+ ) ) ;
1085
+ assert_eq ! (
1086
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . benchmark_set( ) ,
1087
+ & benchmark_set
1088
+ ) ;
1033
1089
1034
- dbg ! ( "{:?}" , status_page_data) ;
1090
+ // test the second job
1091
+ assert ! ( matches!(
1092
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . target( ) ,
1093
+ Target :: X86_64UnknownLinuxGnu
1094
+ ) ) ;
1095
+ assert ! ( matches!(
1096
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . status( ) ,
1097
+ BenchmarkJobStatus :: Queued
1098
+ ) ) ;
1099
+ assert ! ( matches!(
1100
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . backend( ) ,
1101
+ CodegenBackend :: Llvm
1102
+ ) ) ;
1103
+ assert ! ( matches!(
1104
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . profile( ) ,
1105
+ Profile :: Debug
1106
+ ) ) ;
1107
+ assert_eq ! (
1108
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . benchmark_set( ) ,
1109
+ & benchmark_set
1110
+ ) ;
1035
1111
1036
1112
Ok ( ctx)
1037
1113
} )
0 commit comments