Bug 1444068 - Switch to using rust time for Marionette connection polling draft
authorGreg Fraley <gsfraley@gmail.com>
Sat, 17 Mar 2018 17:32:49 -0400
changeset 769285 880b2a021a6f9a0a81dfa5bee880232daf8cd722
parent 769283 38f424da56206f0946ddd01b3c9b1ce5bf195739
child 769286 cd0fee0fc56e9810276219ea4c08e43ca59c9e42
push id103089
push userbmo:gsfraley@gmail.com
push dateMon, 19 Mar 2018 10:35:33 +0000
bugs1444068
milestone61.0a1
Bug 1444068 - Switch to using rust time for Marionette connection polling Foremost, this patch switches to using time::Instant and time::Duration to handle the state of polling against the Marionette connection. It also replaces the trace call to printout the progress of the polling with a debug statement upfront indicating total poll time. MozReview-Commit-ID: 2y6twJovMr6
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(),
                         ));
                     }
                 }
             }