Bug 1429562 - Remove obsolete optional parameter `reset_session_id` from `delete_session`. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 11 Jan 2018 12:24:15 +0100
changeset 719029 30ee586de9a637330c7392520bce4c96f2252213
parent 719011 c2953fa3577168bcd574761ab452490e1e0e4fc7
child 745689 1d67291eeba58a79f0ae8d1bfd2f2324bd646f28
push id95142
push userbmo:hskupin@gmail.com
push dateThu, 11 Jan 2018 11:51:21 +0000
bugs1429562
milestone59.0a1
Bug 1429562 - Remove obsolete optional parameter `reset_session_id` from `delete_session`. By calling "delete_session" the currently used session id always has to be reset, because each session has its own unique id. MozReview-Commit-ID: H9RiuNj7fRd
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/harness/marionette_harness/tests/unit/test_session.py
testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -815,17 +815,17 @@ class Marionette(object):
                 if crash_count > 0:
                     if returncode == 0:
                         message = 'Content process crashed'
                     else:
                         message = 'Process crashed (Exit code: {returncode})'
                 else:
                     message = 'Process has been unexpectedly closed (Exit code: {returncode})'
 
-                self.delete_session(send_request=False, reset_session_id=True)
+                self.delete_session(send_request=False)
 
             message += ' (Reason: {reason})'
 
             raise IOError, message.format(returncode=returncode, reason=val), tb
 
     @staticmethod
     def convert_keys(*string):
         typing = []
@@ -1084,31 +1084,30 @@ class Marionette(object):
                 if not callable(callback):
                     raise ValueError("Specified callback '{}' is not callable".format(callback))
 
                 self._send_message("acceptConnections", {"value": False})
                 callback()
             else:
                 cause = self._request_in_app_shutdown()
 
-            # Ensure to explicitely mark the session as deleted
-            self.delete_session(send_request=False, reset_session_id=True)
+            self.delete_session(send_request=False)
 
             # Give the application some time to shutdown
             returncode = self.instance.runner.wait(timeout=self.DEFAULT_SHUTDOWN_TIMEOUT)
             if returncode is None:
                 # This will force-close the application without sending any other message.
                 self.cleanup()
 
                 message = ("Process killed because a requested application quit did not happen "
                            "within {}s. Check gecko.log for errors.")
                 raise IOError(message.format(self.DEFAULT_SHUTDOWN_TIMEOUT))
 
         else:
-            self.delete_session(reset_session_id=True)
+            self.delete_session()
             self.instance.close(clean=clean)
 
         if cause not in (None, "shutdown"):
             raise errors.MarionetteException("Unexpected shutdown reason '{}' for "
                                              "quitting the process.".format(cause))
 
     @do_process_check
     def restart(self, clean=False, in_app=False, callback=None):
@@ -1139,18 +1138,17 @@ class Marionette(object):
                 if not callable(callback):
                     raise ValueError("Specified callback '{}' is not callable".format(callback))
 
                 self._send_message("acceptConnections", {"value": False})
                 callback()
             else:
                 cause = self._request_in_app_shutdown("eRestart")
 
-            # Ensure to explicitely mark the session as deleted
-            self.delete_session(send_request=False, reset_session_id=True)
+            self.delete_session(send_request=False)
 
             try:
                 timeout = self.DEFAULT_SHUTDOWN_TIMEOUT + self.DEFAULT_STARTUP_TIMEOUT
                 self.raise_for_port(timeout=timeout)
             except socket.timeout:
                 if self.instance.runner.returncode is not None:
                     exc, val, tb = sys.exc_info()
                     self.cleanup()
@@ -1250,35 +1248,31 @@ class Marionette(object):
     @property
     def test_name(self):
         return self._test_name
 
     @test_name.setter
     def test_name(self, test_name):
         self._test_name = test_name
 
-    def delete_session(self, send_request=True, reset_session_id=False):
+    def delete_session(self, send_request=True):
         """Close the current session and disconnect from the server.
 
         :param send_request: Optional, if `True` a request to close the session on
             the server side will be sent. Use `False` in case of eg. in_app restart()
             or quit(), which trigger a deletion themselves. Defaults to `True`.
-        :param reset_session_id: Optional, if `True` the current session id will
-            be reset, which will require an explicit call to :func:`start_session`
-            before the test can continue. Defaults to `False`.
         """
         try:
             if send_request:
                 self._send_message("deleteSession")
         finally:
-            if reset_session_id:
-                self.session_id = None
-            self.session = None
             self.process_id = None
             self.profile = None
+            self.session = None
+            self.session_id = None
             self.window = None
 
             if self.client is not None:
                 self.client.close()
 
     @property
     def session_capabilities(self):
         """A JSON dictionary representing the capabilities of the
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_session.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_session.py
@@ -3,18 +3,20 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette_driver import errors
 
 from marionette_harness import MarionetteTestCase
 
 
 class TestSession(MarionetteTestCase):
+
     def setUp(self):
         super(TestSession, self).setUp()
+
         self.marionette.delete_session()
 
     def test_new_session_returns_capabilities(self):
         # Sends newSession
         caps = self.marionette.start_session()
 
         # Check that session was created.  This implies the server
         # sent us the sessionId and status fields.
@@ -30,19 +32,21 @@ class TestSession(MarionetteTestCase):
         self.assertIn("rotatable", caps)
 
     def test_get_session_id(self):
         # Sends newSession
         self.marionette.start_session()
 
         self.assertTrue(self.marionette.session_id is not None)
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
+
     def test_session_already_started(self):
         self.marionette.start_session()
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
         with self.assertRaises(errors.SessionNotCreatedException):
             self.marionette._send_message("newSession", {})
 
     def test_no_session(self):
-        with self.assertRaises(errors.InvalidSessionIdException):
+        with self.assertRaisesRegexp(errors.MarionetteException, "Please start a session"):
             self.marionette.get_url()
+
         self.marionette.start_session()
         self.marionette.get_url()
--- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py
+++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py
@@ -91,17 +91,17 @@ class MarionetteProtocol(Protocol):
                 self.logger.error(traceback.format_exc())
                 self.executor.runner.send_message("init_failed")
             else:
                 self.executor.runner.send_message("init_succeeded")
 
     def teardown(self):
         try:
             self.marionette._request_in_app_shutdown()
-            self.marionette.delete_session(send_request=False, reset_session_id=True)
+            self.marionette.delete_session(send_request=False)
         except Exception:
             # This is typically because the session never started
             pass
         if self.marionette is not None:
             del self.marionette
 
     @property
     def is_alive(self):