@@ -17,11 +17,13 @@ use std::cmp::Ordering;
1717use std:: ffi:: OsStr ;
1818use std:: fs;
1919use std:: fs:: File ;
20+ use std:: future:: Future ;
2021use std:: io:: BufWriter ;
2122use std:: io:: Write ;
2223use std:: path:: { Path , PathBuf } ;
2324use std:: process;
2425use std:: process:: { Command , Stdio } ;
26+ use std:: time:: Duration ;
2527use std:: { str, time:: Instant } ;
2628use tokio:: runtime:: Runtime ;
2729
@@ -618,6 +620,7 @@ fn main_result() -> anyhow::Result<i32> {
618620 builder
619621 . worker_threads ( 1 )
620622 . max_blocking_threads ( 1 )
623+ . enable_time ( )
621624 . enable_io ( ) ;
622625 let mut rt = builder. build ( ) . expect ( "built runtime" ) ;
623626
@@ -1084,6 +1087,18 @@ fn bench_published_artifact(
10841087 )
10851088}
10861089
1090+ const COMPILE_BENCHMARK_TIMEOUT : Duration = Duration :: from_secs ( 60 * 30 ) ;
1091+
1092+ async fn with_timeout < F : Future < Output = anyhow:: Result < ( ) > > > ( fut : F ) -> anyhow:: Result < ( ) > {
1093+ match tokio:: time:: timeout ( COMPILE_BENCHMARK_TIMEOUT , fut) . await {
1094+ Ok ( res) => res,
1095+ Err ( _) => Err ( anyhow:: anyhow!(
1096+ "Benchmark timeouted in {} seconds" ,
1097+ COMPILE_BENCHMARK_TIMEOUT . as_secs( )
1098+ ) ) ,
1099+ }
1100+ }
1101+
10871102/// Perform compile benchmarks.
10881103fn bench_compile (
10891104 rt : & mut Runtime ,
@@ -1163,13 +1178,13 @@ fn bench_compile(
11631178 )
11641179 } ,
11651180 & |processor| {
1166- rt. block_on ( benchmark. measure (
1181+ rt. block_on ( with_timeout ( benchmark. measure (
11671182 processor,
11681183 & config. profiles ,
11691184 & config. scenarios ,
11701185 & shared. toolchain ,
11711186 config. iterations ,
1172- ) )
1187+ ) ) )
11731188 } ,
11741189 )
11751190 }
@@ -1181,7 +1196,7 @@ fn bench_compile(
11811196 Category :: Primary ,
11821197 & || eprintln ! ( "Special benchmark commencing (due to `--bench-rustc`)" ) ,
11831198 & |processor| {
1184- rt. block_on ( processor. measure_rustc ( & shared. toolchain ) )
1199+ rt. block_on ( with_timeout ( processor. measure_rustc ( & shared. toolchain ) ) )
11851200 . context ( "measure rustc" )
11861201 } ,
11871202 ) ;
0 commit comments