@@ -18,6 +18,7 @@ const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR";
1818const DEFAULT_ADDR : & str = "127.0.0.1:12345" ;
1919
2020const CONNECT_TIMEOUT_ENV : & str = "TEST_DEVICE_CONNECT_TIMEOUT_SECONDS" ;
21+ /// The default timeout is high to not break slow CI or slow device starts.
2122const DEFAULT_CONNECT_TIMEOUT : Duration = Duration :: from_mins ( 30 ) ;
2223
2324macro_rules! t {
@@ -59,6 +60,17 @@ fn main() {
5960 }
6061}
6162
63+ fn connect_timeout ( ) -> Duration {
64+ match env:: var ( CONNECT_TIMEOUT_ENV ) . ok ( ) {
65+ Some ( timeout) => timeout. parse ( ) . map ( Duration :: from_secs) . unwrap_or_else ( |e| {
66+ panic ! (
67+ "error: parsing `{CONNECT_TIMEOUT_ENV}` value \" {timeout}\" as seconds failed: {e}"
68+ )
69+ } ) ,
70+ None => DEFAULT_CONNECT_TIMEOUT ,
71+ }
72+ }
73+
6274fn spawn_emulator ( target : & str , server : & Path , tmpdir : & Path , rootfs : Option < PathBuf > ) {
6375 let device_address = env:: var ( REMOTE_ADDR_ENV ) . unwrap_or ( DEFAULT_ADDR . to_string ( ) ) ;
6476
@@ -71,17 +83,11 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option<Pat
7183 start_qemu_emulator ( target, rootfs, server, tmpdir) ;
7284 }
7385
74- // Wait for the emulator to come online
75- let mut total_dur = Duration :: from_secs ( 0 ) ;
76- let timeout = env:: var ( CONNECT_TIMEOUT_ENV ) . ok ( ) . map_or ( DEFAULT_CONNECT_TIMEOUT , |timeout| {
77- let seconds = timeout. parse :: < u64 > ( ) . unwrap_or_else ( |_| {
78- panic ! ( "The {CONNECT_TIMEOUT_ENV} env variable is not a valid integer" ) ;
79- } ) ;
80- Duration :: from_secs ( seconds)
81- } ) ;
82-
86+ let timeout = connect_timeout ( ) ;
8387 let mut timed_out = true ;
8488
89+ // Wait for the emulator to come online
90+ let mut total_dur = Duration :: from_secs ( 0 ) ;
8591 while total_dur < timeout {
8692 let dur = Duration :: from_millis ( 2000 ) ;
8793 if let Ok ( mut client) = TcpStream :: connect ( & device_address) {
0 commit comments