Skip to content

Commit

Permalink
Do not block waiting for chromedriver to start up (#46126)
Browse files Browse the repository at this point in the history
This would save approximately 0.5 second on each test runner restarts.
And this should not cause a problem as another connection to the
webdriver will be made to init the session, which also happens during
initialization stage.

https://github.com/web-platform-tests/wpt/blob/master/tools/wptrunner/wptrunner/testrunner.py#L93
  • Loading branch information
WeizhongX authored May 9, 2024
1 parent 84b308d commit f9487b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
22 changes: 1 addition & 21 deletions tools/wptrunner/wptrunner/browsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import os
import platform
import socket
import time
import traceback
from abc import ABCMeta, abstractmethod
from typing import cast, Any, List, Mapping, Optional, Tuple, Type

import mozprocess
from mozdebug import DebuggerInfo
from mozlog.structuredlog import StructuredLogger

from ..environment import wait_for_service
from ..testloader import GroupMetadata
from ..wptcommandline import require_arg # noqa: F401
from ..wpttest import Test
Expand Down Expand Up @@ -319,7 +316,6 @@ def __init__(self,
self.env = os.environ.copy() if env is None else env
self.webdriver_args = webdriver_args if webdriver_args is not None else []

self.init_deadline: Optional[float] = None
self._output_handler: Optional[OutputHandler] = None
self._cmd = None
self._proc: Optional[mozprocess.ProcessHandler] = None
Expand All @@ -330,7 +326,6 @@ def make_command(self) -> List[str]:
return [self.webdriver_binary] + self.webdriver_args

def start(self, group_metadata: GroupMetadata, **kwargs: Any) -> None:
self.init_deadline = time.time() + self.init_timeout
try:
self._run_server(group_metadata, **kwargs)
except KeyboardInterrupt:
Expand All @@ -345,7 +340,6 @@ def create_output_handler(self, cmd: List[str]) -> OutputHandler:
return OutputHandler(self.logger, cmd)

def _run_server(self, group_metadata: GroupMetadata, **kwargs: Any) -> None:
assert self.init_deadline is not None
cmd = self.make_command()
self._output_handler = self.create_output_handler(cmd)

Expand All @@ -365,21 +359,7 @@ def _run_server(self, group_metadata: GroupMetadata, **kwargs: Any) -> None:
raise
self._output_handler.after_process_start(self._proc.pid)

try:
wait_for_service(
self.logger,
self.host,
self.port,
timeout=self.init_deadline - time.time(),
server_process=self._proc,
)
except Exception:
self.logger.error(
"WebDriver was not accessible "
f"within the timeout:\n{traceback.format_exc()}")
raise
finally:
self._output_handler.start(group_metadata=group_metadata, **kwargs)
self._output_handler.start(group_metadata=group_metadata, **kwargs)
self.logger.debug("_run complete")

def stop(self, force: bool = False) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions tools/wptrunner/wptrunner/browsers/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ def __init__(self, logger, binary, package_name, prefs_root, webdriver_binary, w
self.binary = binary
self.package_name = package_name
self.webdriver_binary = webdriver_binary
self.init_deadline = None

self.stackfix_dir = stackfix_dir
self.symbols_path = symbols_path
Expand Down Expand Up @@ -958,6 +959,7 @@ def create_output_handler(self, cmd):

def start(self, group_metadata, **kwargs):
self.leak_report_file = setup_leak_report(self.leak_check, self.profile, self.env)
self.init_deadline = time.time() + self.init_timeout
super().start(group_metadata, **kwargs)

def stop(self, force=False):
Expand Down
22 changes: 8 additions & 14 deletions tools/wptrunner/wptrunner/tests/browsers/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import sys
from os.path import dirname, join
from unittest import mock

import pytest

Expand Down Expand Up @@ -30,19 +29,14 @@ def test_logging_immediate_exit():
handler = MozLogTestHandler()
logger.add_handler(handler)

class CustomException(Exception):
pass

with mock.patch.object(base, "wait_for_service", side_effect=CustomException):
browser = base.WebDriverBrowser(
logger, webdriver_binary="echo", webdriver_args=["sample output"]
)
try:
with pytest.raises(CustomException):
browser.start(group_metadata={})
finally:
# Ensure the `echo` process actually exits
browser._proc.wait()
browser = base.WebDriverBrowser(
logger, webdriver_binary="echo", webdriver_args=["sample output"]
)
try:
browser.start(group_metadata={})
finally:
# Ensure the `echo` process actually exits
browser._proc.wait()

process_output_actions = [
data for data in handler.items if data["action"] == "process_output"
Expand Down

0 comments on commit f9487b0

Please sign in to comment.