@@ -2,7 +2,7 @@ use crate::selector::CompileTestCase;
2
2
use crate :: {
3
3
ArtifactCollection , ArtifactId , ArtifactIdNumber , BenchmarkJob , BenchmarkJobConclusion ,
4
4
BenchmarkRequest , BenchmarkRequestIndex , BenchmarkRequestStatus , BenchmarkSet , CodegenBackend ,
5
- CollectorConfig , CompileBenchmark , Target ,
5
+ CollectorConfig , CompileBenchmark , PartialStatusPageData , Target ,
6
6
} ;
7
7
use crate :: { CollectionId , Index , Profile , QueuedCommit , Scenario , Step } ;
8
8
use chrono:: { DateTime , Utc } ;
@@ -271,6 +271,8 @@ pub trait Connection: Send + Sync {
271
271
id : u32 ,
272
272
benchmark_job_conculsion : BenchmarkJobConclusion ,
273
273
) -> anyhow:: Result < ( ) > ;
274
+
275
+ async fn get_status_page_data ( & self ) -> anyhow:: Result < PartialStatusPageData > ;
274
276
}
275
277
276
278
#[ async_trait:: async_trait]
@@ -393,6 +395,7 @@ mod tests {
393
395
use super :: * ;
394
396
use crate :: metric:: Metric ;
395
397
use crate :: tests:: run_postgres_test;
398
+ use crate :: BenchmarkJobStatus ;
396
399
use crate :: { tests:: run_db_test, BenchmarkRequestType , Commit , CommitType , Date } ;
397
400
use chrono:: Utc ;
398
401
use std:: str:: FromStr ;
@@ -977,6 +980,142 @@ mod tests {
977
980
let completed = db. load_benchmark_request_index ( ) . await . unwrap ( ) ;
978
981
979
982
assert ! ( completed. contains_tag( "sha-1" ) ) ;
983
+ Ok ( ctx)
984
+ } )
985
+ . await ;
986
+ }
987
+
988
+ #[ tokio:: test]
989
+ async fn get_status_page_data ( ) {
990
+ run_postgres_test ( |ctx| async {
991
+ let db = ctx. db_client ( ) . connection ( ) . await ;
992
+ let benchmark_set = BenchmarkSet ( 0u32 ) ;
993
+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
994
+ let tag = "sha-1" ;
995
+ let tag_two = "sha-2" ;
996
+ let collector_name = "collector-1" ;
997
+ let target = Target :: X86_64UnknownLinuxGnu ;
998
+
999
+ db. add_collector_config ( collector_name, target, benchmark_set. 0 , true )
1000
+ . await
1001
+ . unwrap ( ) ;
1002
+
1003
+ let benchmark_request = BenchmarkRequest :: create_release ( tag, time) ;
1004
+ db. insert_benchmark_request ( & benchmark_request)
1005
+ . await
1006
+ . unwrap ( ) ;
1007
+
1008
+ complete_request ( & * db, tag, collector_name, benchmark_set. 0 , target) . await ;
1009
+ // record a couple of errors against the tag
1010
+ let artifact_id = db. artifact_id ( & ArtifactId :: Tag ( tag. to_string ( ) ) ) . await ;
1011
+
1012
+ db. record_error ( artifact_id, "example-1" , "This is an error" )
1013
+ . await ;
1014
+ db. record_error ( artifact_id, "example-2" , "This is another error" )
1015
+ . await ;
1016
+
1017
+ let benchmark_request_two = BenchmarkRequest :: create_release ( tag_two, time) ;
1018
+ db. insert_benchmark_request ( & benchmark_request_two)
1019
+ . await
1020
+ . unwrap ( ) ;
1021
+
1022
+ db. enqueue_benchmark_job (
1023
+ benchmark_request_two. tag ( ) . unwrap ( ) ,
1024
+ target,
1025
+ CodegenBackend :: Llvm ,
1026
+ Profile :: Opt ,
1027
+ benchmark_set. 0 ,
1028
+ )
1029
+ . await
1030
+ . unwrap ( ) ;
1031
+ db. enqueue_benchmark_job (
1032
+ benchmark_request_two. tag ( ) . unwrap ( ) ,
1033
+ target,
1034
+ CodegenBackend :: Llvm ,
1035
+ Profile :: Debug ,
1036
+ benchmark_set. 0 ,
1037
+ )
1038
+ . await
1039
+ . unwrap ( ) ;
1040
+
1041
+ db. update_benchmark_request_status (
1042
+ benchmark_request_two. tag ( ) . unwrap ( ) ,
1043
+ BenchmarkRequestStatus :: InProgress ,
1044
+ )
1045
+ . await
1046
+ . unwrap ( ) ;
1047
+
1048
+ let status_page_data = db. get_status_page_data ( ) . await . unwrap ( ) ;
1049
+
1050
+ assert ! ( status_page_data. completed_requests. len( ) == 1 ) ;
1051
+ assert_eq ! ( status_page_data. completed_requests[ 0 ] . 0 . tag( ) . unwrap( ) , tag) ;
1052
+ assert ! ( matches!(
1053
+ status_page_data. completed_requests[ 0 ] . 0 . status( ) ,
1054
+ BenchmarkRequestStatus :: Completed { .. }
1055
+ ) ) ;
1056
+ // can't really test duration
1057
+ // ensure errors are correct
1058
+ assert_eq ! (
1059
+ status_page_data. completed_requests[ 0 ] . 2 [ 0 ] ,
1060
+ "This is an error" . to_string( )
1061
+ ) ;
1062
+ assert_eq ! (
1063
+ status_page_data. completed_requests[ 0 ] . 2 [ 1 ] ,
1064
+ "This is another error" . to_string( )
1065
+ ) ;
1066
+
1067
+ assert ! ( status_page_data. in_progress. len( ) == 1 ) ;
1068
+ // we should have 2 jobs
1069
+ assert ! ( status_page_data. in_progress[ 0 ] . 1 . len( ) == 2 ) ;
1070
+ // the request should be in progress
1071
+ assert ! ( matches!(
1072
+ status_page_data. in_progress[ 0 ] . 0 . status( ) ,
1073
+ BenchmarkRequestStatus :: InProgress
1074
+ ) ) ;
1075
+
1076
+ // Test the first job
1077
+ assert ! ( matches!(
1078
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . target( ) ,
1079
+ Target :: X86_64UnknownLinuxGnu
1080
+ ) ) ;
1081
+ assert ! ( matches!(
1082
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . status( ) ,
1083
+ BenchmarkJobStatus :: Queued
1084
+ ) ) ;
1085
+ assert ! ( matches!(
1086
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . backend( ) ,
1087
+ CodegenBackend :: Llvm
1088
+ ) ) ;
1089
+ assert ! ( matches!(
1090
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . profile( ) ,
1091
+ Profile :: Opt
1092
+ ) ) ;
1093
+ assert_eq ! (
1094
+ status_page_data. in_progress[ 0 ] . 1 [ 0 ] . benchmark_set( ) ,
1095
+ benchmark_set
1096
+ ) ;
1097
+
1098
+ // test the second job
1099
+ assert ! ( matches!(
1100
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . target( ) ,
1101
+ Target :: X86_64UnknownLinuxGnu
1102
+ ) ) ;
1103
+ assert ! ( matches!(
1104
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . status( ) ,
1105
+ BenchmarkJobStatus :: Queued
1106
+ ) ) ;
1107
+ assert ! ( matches!(
1108
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . backend( ) ,
1109
+ CodegenBackend :: Llvm
1110
+ ) ) ;
1111
+ assert ! ( matches!(
1112
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . profile( ) ,
1113
+ Profile :: Debug
1114
+ ) ) ;
1115
+ assert_eq ! (
1116
+ status_page_data. in_progress[ 0 ] . 1 [ 1 ] . benchmark_set( ) ,
1117
+ benchmark_set
1118
+ ) ;
980
1119
981
1120
Ok ( ctx)
982
1121
} )
0 commit comments