Bug 1299216 - Remove always parameter from do_process_check decorator. r=automatedtester
authorHenrik Skupin <mail@hskupin.info>
Wed, 21 Sep 2016 12:57:50 +0200
changeset 351603 d57d7ada1080b190a6415134f4d2dab55e382f86
parent 351602 32b908ad1b02660ff9bce79cbae9b8b4e5515a94
child 351604 e7aa936d8b6e3707a29665d9eb6623d21ff5deea
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1299216
milestone52.0a1
Bug 1299216 - Remove always parameter from do_process_check decorator. r=automatedtester 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)