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
--- 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(),
));
}
}
}