Bug 1716963 - Don't call cleanup from __del__ if it already ran, r=webdriver-reviewers,whimboo

Allow marionette users to opt out of __del__ doing any work by first
explictly calling cleanup().

Differential Revision: https://phabricator.services.mozilla.com/D118147
This commit is contained in:
James Graham 2021-07-07 14:22:59 +00:00
Родитель 1bbd67c762
Коммит 83bd42eb4d
2 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -447,7 +447,6 @@ class Marionette(object):
:param app: Type of ``instance_class`` to use for managing app :param app: Type of ``instance_class`` to use for managing app
instance. See ``marionette_driver.geckoinstance``. instance. See ``marionette_driver.geckoinstance``.
:param instance_args: Arguments to pass to ``instance_class``. :param instance_args: Arguments to pass to ``instance_class``.
""" """
self.host = "127.0.0.1" # host self.host = "127.0.0.1" # host
if int(port) == 0: if int(port) == 0:
@ -466,6 +465,7 @@ class Marionette(object):
self._test_name = None self._test_name = None
self.crashed = 0 self.crashed = 0
self.is_shutting_down = False self.is_shutting_down = False
self.cleanup_ran = False
if socket_timeout is None: if socket_timeout is None:
self.socket_timeout = self.DEFAULT_SOCKET_TIMEOUT self.socket_timeout = self.DEFAULT_SOCKET_TIMEOUT
@ -531,9 +531,11 @@ class Marionette(object):
raise errors.UnresponsiveInstanceException( raise errors.UnresponsiveInstanceException(
"Application clean-up has failed >2 consecutive times." "Application clean-up has failed >2 consecutive times."
) )
self.cleanup_ran = True
def __del__(self): def __del__(self):
self.cleanup() if not self.cleanup_ran:
self.cleanup()
@staticmethod @staticmethod
def check_port_available(port, host=""): def check_port_available(port, host=""):
@ -1193,6 +1195,7 @@ class Marionette(object):
self.session_id = resp["sessionId"] self.session_id = resp["sessionId"]
self.session = resp["capabilities"] self.session = resp["capabilities"]
self.cleanup_ran = False
# fallback to processId can be removed in Firefox 55 # fallback to processId can be removed in Firefox 55
self.process_id = self.session.get( self.process_id = self.session.get(
"moz:processID", self.session.get("processId") "moz:processID", self.session.get("processId")

Просмотреть файл

@ -734,11 +734,12 @@ class MarionetteProtocol(Protocol):
try: try:
self.marionette._request_in_app_shutdown() self.marionette._request_in_app_shutdown()
self.marionette.delete_session(send_request=False) self.marionette.delete_session(send_request=False)
self.marionette.cleanup()
except Exception: except Exception:
# This is typically because the session never started # This is typically because the session never started
pass pass
if self.marionette is not None: if self.marionette is not None:
del self.marionette self.marionette = None
super(MarionetteProtocol, self).teardown() super(MarionetteProtocol, self).teardown()
def is_alive(self): def is_alive(self):