Bug 1444068 - Switch to using rust time for Marionette connection polling r=ato draft
authorGreg Fraley <gsfraley@gmail.com>
Mon, 19 Mar 2018 06:41:42 -0400
changeset 769287 77a80f4e2a95bf65e8c4e08ba064bf7e35517bf9
parent 769283 38f424da56206f0946ddd01b3c9b1ce5bf195739
push id103090
push userbmo:gsfraley@gmail.com
push dateMon, 19 Mar 2018 10:43:50 +0000
reviewersato
bugs1444068
milestone61.0a1
Bug 1444068 - Switch to using rust time for Marionette connection polling r=ato MozReview-Commit-ID: LMtDDeRSzcQ
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -1315,21 +1315,21 @@ impl MarionetteConnection {
         MarionetteConnection {
             port: port,
             stream: None,
             session: MarionetteSession::new(session_id),
         }
     }
 
     pub fn connect(&mut self, browser: &mut Option<FirefoxProcess>) -> WebDriverResult<()> {
-        let timeout = 60 * 1000; // ms
-        let poll_interval = 100; // ms
-        let poll_attempts = timeout / poll_interval;
-        let mut poll_attempt = 0;
+        let timeout = time::Duration::from_secs(60);
+        let poll_interval = time::Duration::from_millis(100);
+        let now = time::Instant::now();
 
+        debug!("Waiting {}s to connect to browser", timeout.as_secs());
         loop {
             // immediately abort connection attempts if process disappears
             if let &mut Some(ref mut runner) = browser {
                 let exit_status = match runner.try_wait() {
                     Ok(Some(status)) => Some(
                         status
                             .code()
                             .map(|c| c.to_string())
@@ -1347,20 +1347,18 @@ impl MarionetteConnection {
             }
 
             match TcpStream::connect(&(DEFAULT_HOST, self.port)) {
                 Ok(stream) => {
                     self.stream = Some(stream);
                     break;
                 }
                 Err(e) => {
-                    trace!("  connection attempt {}/{}", poll_attempt, poll_attempts);
-                    if poll_attempt <= poll_attempts {
-                        poll_attempt += 1;
-                        thread::sleep(time::Duration::from_millis(poll_interval));
+                    if now.elapsed() < timeout {
+                        thread::sleep(poll_interval);
                     } else {
                         return Err(WebDriverError::new(
                             ErrorStatus::UnknownError,
                             e.description().to_owned(),
                         ));
                     }
                 }
             }