Bug 809437 - Fix B2G emulator unittest intermittent timeout, r=jgriffin
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 13 Nov 2012 09:32:34 -0500
changeset 113082 a38c6f05ba19b931a77c06833ab908d36a01e13f
parent 113081 d56d537a1843c0b5d8e112d1a2dc301e4728e054
child 113083 e7e6e5b17b70da905086450a689b18fa045e0fb7
push id17933
push userahalberstadt@mozilla.com
push dateTue, 13 Nov 2012 14:33:40 +0000
treeherdermozilla-inbound@a38c6f05ba19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs809437
milestone19.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 809437 - Fix B2G emulator unittest intermittent timeout, r=jgriffin
testing/marionette/client/marionette/emulator.py
--- a/testing/marionette/client/marionette/emulator.py
+++ b/testing/marionette/client/marionette/emulator.py
@@ -368,26 +368,53 @@ waitFor(
 
     def _save_logcat_proc(self, filename, cmd):
         self.logcat_proc = LogcatProc(filename, cmd)
         self.logcat_proc.run()
         self.logcat_proc.processOutput()
         self.logcat_proc.waitForFinish()
         self.logcat_proc = None
 
+    def _restart_b2g(self, marionette):
+        self.dm.shellCheckOutput(['stop', 'b2g'])
+
+        # ensure the b2g process has fully stopped
+        for i in range(0, 10):
+            time.sleep(1)
+            if self.dm.processExist('b2g') is None:
+                break
+        else:
+            raise TimeoutException("Timeout waiting for the b2g process to terminate")
+
+        self.dm.shellCheckOutput(['start', 'b2g'])
+
+        # ensure the b2g process has started
+        for i in range(0, 10):
+            time.sleep(1)
+            if self.dm.processExist('b2g') is not None:
+                break
+        else:
+            raise TimeoutException("Timeout waiting for the b2g process to start")
+
+        if not self.wait_for_port():
+            raise TimeoutException("Timeout waiting for marionette on port '%s'" % self.marionette_port)
+        self.wait_for_system_message(marionette)
+
+
     def install_gecko(self, gecko_path, marionette):
         """
         Install gecko into the emulator using adb push.  Restart b2g after the
         installation.
         """
         # See bug 800102.  We use this particular method of installing
         # gecko in order to avoid an adb bug in which adb will sometimes
         # hang indefinitely while copying large files to the system
         # partition.
         push_attempts = 10
+        restart_attempts = 10
 
         print 'installing gecko binaries...'
         # need to remount so we can write to /system/b2g
         self._run_adb(['remount'])
         for root, dirs, files in os.walk(gecko_path):
             for filename in files:
                 rel_path = os.path.relpath(os.path.join(root, filename), gecko_path)
                 system_b2g_file = os.path.join('/system/b2g', rel_path)
@@ -395,30 +422,25 @@ waitFor(
                     print 'pushing', system_b2g_file, '(attempt %s of %s)' % (retry, push_attempts)
                     try:
                         self.dm.pushFile(os.path.join(root, filename), system_b2g_file)
                         break
                     except DMError:
                         if retry == push_attempts:
                             raise
 
-        print 'restarting B2G'
-        self.dm.shellCheckOutput(['stop', 'b2g'])
-        # ensure the b2g process has fully stopped (bug 809437)
-        for i in range(0, 10):
-            time.sleep(1)
-            if self.dm.processExist('b2g') is None:
+        for retry in range(1, restart_attempts+1):
+            print 'restarting B2G (attempt %s of %s)' % (retry, restart_attempts)
+            try:
+                self._restart_b2g(marionette)
                 break
-        else:
-            raise TimeoutException("Timeout waiting for the b2g process to terminate")
-        self.dm.shellCheckOutput(['start', 'b2g'])
+            except MarionetteException, TimeoutException:
+                if retry == restart_attmempts:
+                    raise
 
-        if not self.wait_for_port():
-            raise TimeoutException("Timeout waiting for marionette on port '%s'" % self.marionette_port)
-        self.wait_for_system_message(marionette)
 
     def rotate_log(self, srclog, index=1):
         """ Rotate a logfile, by recursively rotating logs further in the sequence,
             deleting the last file if necessary.
         """
         destlog = os.path.join(self.logcat_dir, 'emulator-%d.%d.log' % (self.port, index))
         if os.access(destlog, os.F_OK):
             if index == 3: