Bug 1521967 - Part 2: Drop sleeps in `mach raptor-test` when running locally. r=rwood
authorNick Alexander <nalexander@mozilla.com>
Mon, 18 Mar 2019 16:50:57 +0000
changeset 464865 b010581c27e8a3363ed85fa9bcb9dd410133e9ab
parent 464864 7ac6d4f7327e6fb27be6af341e123d60ea902bac
child 464866 2f95100eef2277c77140165bfcc399dd11a07b4d
push id80748
push usernalexander@mozilla.com
push dateMon, 18 Mar 2019 19:43:01 +0000
treeherderautoland@b010581c27e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrwood
bugs1521967
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521967 - Part 2: Drop sleeps in `mach raptor-test` when running locally. r=rwood I don't know why we're sleeping around `certutil` invocations at all, but let's at least not spend 10s of seconds doing nothing locally. Differential Revision: https://phabricator.services.mozilla.com/D17398
testing/mozbase/mozproxy/mozproxy/backends/mitm.py
--- a/testing/mozbase/mozproxy/mozproxy/backends/mitm.py
+++ b/testing/mozbase/mozproxy/mozproxy/backends/mitm.py
@@ -36,19 +36,16 @@ except Exception:
         ".mitmproxy",
         "mitmproxy-ca-cert.cer",
     )
 
 # On Windows, deal with mozilla-build having forward slashes in $HOME:
 if os.name == "nt" and "/" in DEFAULT_CERT_PATH:
     DEFAULT_CERT_PATH = DEFAULT_CERT_PATH.replace("/", "\\")
 
-# sleep in seconds after issuing a `mitmdump` command
-MITMDUMP_SLEEP = 10
-
 # to install mitmproxy certificate into Firefox and turn on/off proxy
 POLICIES_CONTENT_ON = """{
   "policies": {
     "Certificates": {
       "Install": ["%(cert)s"]
     },
     "Proxy": {
       "Mode": "manual",
@@ -113,16 +110,21 @@ class Mitmproxy(Playback):
 
         # In case the setup fails, we want to stop the process before raising.
         try:
             self.setup()
         except Exception:
             self.stop()
             raise
 
+    @property
+    def mitmdump_sleep_seconds(self):
+        """Time to sleep, in seconds, after issuing a `mitmdump` command."""
+        return 10 if not self.config['run_local'] else 1
+
     def download(self):
         """Download and unpack mitmproxy binary and pageset using tooltool"""
         if not os.path.exists(self.mozproxy_dir):
             os.makedirs(self.mozproxy_dir)
 
         LOG.info("downloading mitmproxy binary")
         _manifest = os.path.join(here, self.config["playback_binary_manifest"])
         transformed_manifest = transform_platform(_manifest, self.config["platform"])
@@ -177,17 +179,17 @@ class Mitmproxy(Playback):
         mitmproxy_proc = ProcessHandler(command,
                                         logfile=os.path.join(self.upload_dir,
                                                              "mitmproxy.log"),
                                         env=env)
         mitmproxy_proc.run()
 
         # XXX replace the code below with a loop with a connection attempt
         # Bug 1532557
-        time.sleep(MITMDUMP_SLEEP)
+        time.sleep(self.mitmdump_sleep_seconds)
         data = mitmproxy_proc.poll()
         if data is None:  # None value indicates process hasn't terminated
             LOG.info(
                 "Mitmproxy playback successfully started as pid %d" % mitmproxy_proc.pid
             )
             return mitmproxy_proc
         # cannot continue as we won't be able to playback the pages
         LOG.error(
@@ -198,17 +200,17 @@ class Mitmproxy(Playback):
         sys.exit()
 
     def stop_mitmproxy_playback(self):
         """Stop the mitproxy server playback"""
         mitmproxy_proc = self.mitmproxy_proc
         LOG.info("Stopping mitmproxy playback, killing process %d" % mitmproxy_proc.pid)
         mitmproxy_proc.kill()
 
-        time.sleep(MITMDUMP_SLEEP)
+        time.sleep(self.mitmdump_sleep_seconds)
         status = mitmproxy_proc.poll()
         if status is None:  # None value indicates process hasn't terminated
             # I *think* we can still continue, as process will be automatically
             # killed anyway when mozharness is done (?) if not, we won't be able
             # to startup mitmxproy next time if it is already running
             LOG.error("Failed to kill the mitmproxy playback process")
             LOG.info(str(status))
         else:
@@ -324,16 +326,21 @@ class MitmproxyDesktop(Mitmproxy):
             )
 
 
 class MitmproxyAndroid(Mitmproxy):
     def __init__(self, config, android_device):
         Mitmproxy.__init__(self, config)
         self.android_device = android_device
 
+    @property
+    def certutil_sleep_seconds(self):
+        """Time to sleep, in seconds, after issuing a `certutil` command."""
+        return 10 if not self.config['run_local'] else 1
+
     def setup(self):
         """For geckoview we need to install the generated mitmproxy CA cert"""
         if self.config["app"] in ["geckoview", "refbrow", "fenix"]:
             # install the generated CA certificate into android geckoview
             self.install_mitmproxy_cert(self.mitmproxy_proc, self.browser_path)
 
     def install_mitmproxy_cert(self, mitmproxy_proc, browser_path):
         """Install the CA certificate generated by mitmproxy, into geckoview android
@@ -346,17 +353,16 @@ class MitmproxyAndroid(Mitmproxy):
 
         Then, both locally and in production:
         1. Create an NSS certificate database in the geckoview browser profile dir, only
            if it doesn't already exist. Use this certutil command:
            `certutil -N -d sql:<path to profile> --empty-password`
         2. Import the mitmproxy certificate into the database, i.e.:
            `certutil -A -d sql:<path to profile> -n "some nickname" -t TC,, -a -i <path to CA.pem>`
         """
-        self.CERTUTIL_SLEEP = 10
         if self.config['run_local']:
             # when running locally, it is found in the Firefox desktop build (..obj../dist/bin)
             self.certutil = os.path.join(os.environ['MOZ_HOST_BIN'], 'certutil')
             if not (os.path.isfile(self.certutil) and os.access(self.certutil, os.X_OK)):
                 LOG.critical("Abort: unable to execute certutil: {}".format(self.certutil))
                 raise
             self.certutil = os.environ['MOZ_HOST_BIN']
             os.environ['LD_LIBRARY_PATH'] = self.certutil
@@ -429,27 +435,27 @@ class MitmproxyAndroid(Mitmproxy):
             LOG.info("the nss cert db already exists")
             cert_db_exists = True
         except subprocess.CalledProcessError:
             # this means the nss cert db doesn't exist yet
             LOG.info("nss cert db doesn't exist yet")
             cert_db_exists = False
 
         # try a forced pause between certutil cmds; possibly reduce later
-        time.sleep(self.CERTUTIL_SLEEP)
+        time.sleep(self.certutil_sleep_seconds)
 
         if not cert_db_exists:
             # create cert db if it doesn't already exist; it may exist already
             # if a previous pageload test ran in the same test suite
             param1 = "sql:%s/" % self.config["local_profile_dir"]
             command = [self.certutil, "-N", "-v", "-d", param1, "--empty-password"]
 
             LOG.info("creating nss cert database using command: %s" % " ".join(command))
             cmd_proc = subprocess.Popen(command, env=os.environ.copy())
-            time.sleep(self.CERTUTIL_SLEEP)
+            time.sleep(self.certutil_sleep_seconds)
             cmd_terminated = cmd_proc.poll()
             if cmd_terminated is None:  # None value indicates process hasn't terminated
                 LOG.critical("nss cert db creation command failed to complete")
                 raise
 
         # import mitmproxy cert into the db
         command = [
             self.certutil,
@@ -464,17 +470,17 @@ class MitmproxyAndroid(Mitmproxy):
             "-i",
             self.local_cert_path,
         ]
 
         LOG.info(
             "importing mitmproxy cert into db using command: %s" % " ".join(command)
         )
         cmd_proc = subprocess.Popen(command, env=os.environ.copy())
-        time.sleep(self.CERTUTIL_SLEEP)
+        time.sleep(self.certutil_sleep_seconds)
         cmd_terminated = cmd_proc.poll()
         if cmd_terminated is None:  # None value indicates process hasn't terminated
             LOG.critical(
                 "command to import mitmproxy cert into cert db failed to complete"
             )
 
         # cannot continue if failed to add CA cert to Firefox, need to check
         if not self.is_mitmproxy_cert_installed():
@@ -497,16 +503,16 @@ class MitmproxyAndroid(Mitmproxy):
             cmd_output = subprocess.check_output(command, env=os.environ.copy())
 
         except subprocess.CalledProcessError:
             # cmd itself failed
             LOG.critical("certutil command failed")
             raise
 
         # check output from the certutil command, see if 'mitmproxy-cert' is listed
-        time.sleep(self.CERTUTIL_SLEEP)
+        time.sleep(self.certutil_sleep_seconds)
         LOG.info(cmd_output)
         if "mitmproxy-cert" in cmd_output:
             LOG.info(
                 "verfied the mitmproxy-cert is installed in the nss cert db on android"
             )
             return True
         return False