Bug 1299216 - Remove always parameter from do_process_check decorator. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 21 Sep 2016 12:57:50 +0200
changeset 435304 bc4f6e73b9d49cda6c251ba5360f984bb626daa4
parent 435303 090f868fde153f479cdbf11c703fe73d8cd4b083
child 435305 06bf39a1b60975d418af6302ec3764b5661b5b2e
push id34992
push userbmo:hskupin@gmail.com
push dateTue, 08 Nov 2016 11:06:47 +0000
bugs1299216
milestone52.0a1
Bug 1299216 - Remove always parameter from do_process_check decorator. Removing the always parameter which is kinda useless here. Originally it was added to call check_for_crash() in case of a MarionetteException happening. But such an exception is never thrown in case of crashes. It will always be an IOError. So lets get it removed and ensure we call check_for_crashes() in all the cases, and can feed the crash status into the call to handle_socket_failure(). MozReview-Commit-ID: JeK3X7voocD
testing/marionette/client/marionette_driver/decorators.py
--- a/testing/marionette/client/marionette_driver/decorators.py
+++ b/testing/marionette/client/marionette_driver/decorators.py
@@ -1,71 +1,51 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-from errors import MarionetteException
 from functools import wraps
 import socket
 import sys
 import traceback
 
 
 def _find_marionette_in_args(*args, **kwargs):
     try:
         m = [a for a in args + tuple(kwargs.values()) if hasattr(a, 'session')][0]
     except IndexError:
         print("Can only apply decorator to function using a marionette object")
         raise
     return m
 
 
-def do_process_check(func, always=False):
-    """Decorator which checks the process after the function has run.
-
-    There is a check for crashes which always gets executed. And in the case of
-    connection issues the process will be force closed.
-
-    :param always: If False, only checks for crashes if an exception
-                   was raised. If True, always checks for crashes.
-    """
+def do_process_check(func):
+    """Decorator which checks the process status after the function has run."""
     @wraps(func)
     def _(*args, **kwargs):
         m = _find_marionette_in_args(*args, **kwargs)
 
-        def check_for_crash():
+        try:
+            return func(*args, **kwargs)
+        except IOError as e:
+            exc, val, tb = sys.exc_info()
+            crashed = False
+
             try:
-                return m.check_for_crash()
+                crashed = m.check_for_crash()
             except Exception:
                 # don't want to lose the original exception
                 traceback.print_exc()
 
-                return False
-
-        try:
-            return func(*args, **kwargs)
-        except (MarionetteException, IOError) as e:
-            exc, val, tb = sys.exc_info()
-            crashed = False
-
-            # In case of no Marionette failures ensure to check for possible crashes.
-            # Do it before checking for port disconnects, to avoid reporting of unrelated
-            # crashes due to a forced shutdown of the application.
-            if not isinstance(e, MarionetteException) or type(e) is MarionetteException:
-                if not always:
-                    crashed = check_for_crash()
-
             # In case of socket failures force a shutdown of the application
             if type(e) in (socket.error, socket.timeout) or crashed:
                 m.handle_socket_failure(crashed)
 
             raise exc, val, tb
-        finally:
-            if always:
-                check_for_crash()
+
     return _
 
 
 def uses_marionette(func):
     """Decorator which creates a marionette session and deletes it
     afterwards if one doesn't already exist.
     """
     @wraps(func)