@@ -241,6 +241,7 @@ pub trait Connection: Send + Sync {
241241
242242 /// Add a benchmark job to the job queue and returns its ID, if it was not
243243 /// already in the DB previously.
244+ #[ allow( clippy:: too_many_arguments) ]
244245 async fn enqueue_benchmark_job (
245246 & self ,
246247 request_tag : & str ,
@@ -249,6 +250,7 @@ pub trait Connection: Send + Sync {
249250 profile : Profile ,
250251 benchmark_set : u32 ,
251252 kind : BenchmarkJobKind ,
253+ is_optional : bool ,
252254 ) -> JobEnqueueResult ;
253255
254256 /// Returns a set of compile-time benchmark test cases that were already computed for the
@@ -747,6 +749,7 @@ mod tests {
747749 Profile :: Opt ,
748750 0u32 ,
749751 BenchmarkJobKind :: Runtime ,
752+ false ,
750753 )
751754 . await ;
752755 match result {
@@ -906,6 +909,7 @@ mod tests {
906909 Profile :: Opt ,
907910 1u32 ,
908911 BenchmarkJobKind :: Runtime ,
912+ false ,
909913 )
910914 . await
911915 {
@@ -1006,6 +1010,7 @@ mod tests {
10061010 Profile :: Opt ,
10071011 benchmark_set. 0 ,
10081012 BenchmarkJobKind :: Runtime ,
1013+ false ,
10091014 )
10101015 . await
10111016 . unwrap ( ) ;
@@ -1260,6 +1265,7 @@ mod tests {
12601265 Profile :: Check ,
12611266 0 ,
12621267 BenchmarkJobKind :: Compiletime ,
1268+ false ,
12631269 )
12641270 . await
12651271 . unwrap ( ) ;
@@ -1286,4 +1292,98 @@ mod tests {
12861292 } )
12871293 . await ;
12881294 }
1295+
1296+ #[ tokio:: test]
1297+ async fn optional_jobs_should_not_block_benchmark_request_from_being_completed ( ) {
1298+ run_postgres_test ( |ctx| async {
1299+ let db = ctx. db ( ) ;
1300+ let time = chrono:: DateTime :: from_str ( "2021-09-01T00:00:00.000Z" ) . unwrap ( ) ;
1301+ let benchmark_set = BenchmarkSet ( 0u32 ) ;
1302+ let tag = "sha-1" ;
1303+ let collector_name = "collector-1" ;
1304+ let target = Target :: X86_64UnknownLinuxGnu ;
1305+
1306+ let insert_result = db
1307+ . add_collector_config ( collector_name, target, 1 , true )
1308+ . await ;
1309+ assert ! ( insert_result. is_ok( ) ) ;
1310+
1311+ /* Create the request */
1312+ let benchmark_request = BenchmarkRequest :: create_release ( tag, time) ;
1313+ db. insert_benchmark_request ( & benchmark_request)
1314+ . await
1315+ . unwrap ( ) ;
1316+
1317+ /* Create job for the request */
1318+ db. enqueue_benchmark_job (
1319+ benchmark_request. tag ( ) . unwrap ( ) ,
1320+ target,
1321+ CodegenBackend :: Llvm ,
1322+ Profile :: Opt ,
1323+ benchmark_set. 0 ,
1324+ BenchmarkJobKind :: Runtime ,
1325+ false ,
1326+ )
1327+ . await
1328+ . unwrap ( ) ;
1329+
1330+ /* Create optional job for the request, this is somewhat unrealsitic
1331+ * as we're only going to make specific targets jobs optional */
1332+ db. enqueue_benchmark_job (
1333+ benchmark_request. tag ( ) . unwrap ( ) ,
1334+ target,
1335+ CodegenBackend :: Llvm ,
1336+ Profile :: Doc ,
1337+ benchmark_set. 0 ,
1338+ BenchmarkJobKind :: Runtime ,
1339+ true ,
1340+ )
1341+ . await
1342+ . unwrap ( ) ;
1343+
1344+ let ( job, _) = db
1345+ . dequeue_benchmark_job ( collector_name, target, benchmark_set)
1346+ . await
1347+ . unwrap ( )
1348+ . unwrap ( ) ;
1349+
1350+ assert_eq ! ( job. request_tag( ) , benchmark_request. tag( ) . unwrap( ) ) ;
1351+
1352+ /* Make the job take some amount of time */
1353+ tokio:: time:: sleep ( Duration :: from_millis ( 1000 ) ) . await ;
1354+
1355+ /* Mark the job as complete */
1356+ db. mark_benchmark_job_as_completed ( job. id ( ) , BenchmarkJobConclusion :: Success )
1357+ . await
1358+ . unwrap ( ) ;
1359+
1360+ db. maybe_mark_benchmark_request_as_completed ( tag)
1361+ . await
1362+ . unwrap ( ) ;
1363+
1364+ /* From the status page view we can see that the duration has been
1365+ * updated. Albeit that it will be a very short duration. */
1366+ let completed = db. get_last_n_completed_benchmark_requests ( 1 ) . await . unwrap ( ) ;
1367+ let req = & completed
1368+ . iter ( )
1369+ . find ( |it| it. request . tag ( ) == Some ( tag) )
1370+ . unwrap ( )
1371+ . request ;
1372+
1373+ assert ! ( matches!(
1374+ req. status( ) ,
1375+ BenchmarkRequestStatus :: Completed { .. }
1376+ ) ) ;
1377+ let BenchmarkRequestStatus :: Completed { duration, .. } = req. status ( ) else {
1378+ unreachable ! ( ) ;
1379+ } ;
1380+ assert ! ( duration >= Duration :: from_millis( 1000 ) ) ;
1381+
1382+ let completed_index = db. load_benchmark_request_index ( ) . await . unwrap ( ) ;
1383+ assert ! ( completed_index. contains_tag( "sha-1" ) ) ;
1384+
1385+ Ok ( ctx)
1386+ } )
1387+ . await ;
1388+ }
12891389}
0 commit comments