Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wptrunner] Stop the runner process before the browser #48030

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ def connect(self):
self.webdriver.start()

def teardown(self):
if not self.webdriver:
return
self.logger.debug("Hanging up on WebDriver session")
try:
self.webdriver.end()
Expand Down
19 changes: 11 additions & 8 deletions tools/wptrunner/wptrunner/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,13 +959,15 @@ def stop_runner(self, force=False):
if self.test_runner_proc is None:
return

if self.test_runner_proc.is_alive():
self.send_message("stop")
try:
# Stop the runner process before the browser process so that the
# former can gracefully tear down the protocol (e.g., closing an
# active WebDriver session).
self._ensure_runner_stopped()
self.browser.stop(force=force)
self.ensure_runner_stopped()
except (OSError, PermissionError):
self.logger.error("Failed to stop the runner")
self.logger.error("Failed to stop either the runner or the browser process",
exc_info=True)
finally:
self.cleanup()

Expand All @@ -978,12 +980,12 @@ def teardown(self):
self.remote_queue = None
self.recording.pause()

def ensure_runner_stopped(self):
self.logger.debug("ensure_runner_stopped")
def _ensure_runner_stopped(self):
if self.test_runner_proc is None:
jonathan-j-lee marked this conversation as resolved.
Show resolved Hide resolved
return

self.browser.stop(force=True)
jonathan-j-lee marked this conversation as resolved.
Show resolved Hide resolved
self.logger.debug("Stopping runner process")
self.send_message("stop")
self.test_runner_proc.join(10)
mp = mpcontext.get_context()
if self.test_runner_proc.is_alive():
Expand All @@ -1009,7 +1011,8 @@ def ensure_runner_stopped(self):
self.logger.debug("Runner process exited with code %i" % self.test_runner_proc.exitcode)

def runner_teardown(self):
jonathan-j-lee marked this conversation as resolved.
Show resolved Hide resolved
self.ensure_runner_stopped()
# No need to stop the runner or browser processes here. It will be done
# when the `stop` state terminates the `TestRunnerManager` run loop.
return RunnerManagerState.stop(False)

def send_message(self, command, *args):
Expand Down
Loading