Bug 967799 - b2gautomation: Wait on the queue instead of polling it. r=ahal, a=bajaj B2G_1_1_20140428_MERGEDAY
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 11 Feb 2014 13:43:33 -0500
changeset 120033 952236c0493c9184ce16480a1d8d8b33d9df9d7c
parent 120032 170d87349060151fbc6f29dbe645c24aedbc598c
child 120034 a69e9e9e56c64e2c7777bda3cdb04160a56c1074
push id1160
push userryanvm@gmail.com
push dateThu, 03 Apr 2014 16:01:52 +0000
reviewersahal, bajaj
bugs967799
milestone18.1
Bug 967799 - b2gautomation: Wait on the queue instead of polling it. r=ahal, a=bajaj
build/mobile/b2gautomation.py
--- a/build/mobile/b2gautomation.py
+++ b/build/mobile/b2gautomation.py
@@ -145,36 +145,33 @@ class B2GRemoteAutomation(Automation):
 
     def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime,
                       debuggerInfo, symbolsPath):
         """ Wait for tests to finish (as evidenced by a signature string
             in logcat), or for a given amount of time to elapse with no
             output.
         """
         timeout = timeout or 120
-        responseDueBy = time.time() + timeout
         while True:
-            currentlog = proc.stdout
+            currentlog = proc.getStdoutLines(timeout)
             if currentlog:
-                responseDueBy = time.time() + timeout
                 print currentlog
                 # Match the test filepath from the last TEST-START line found in the new
                 # log content. These lines are in the form:
                 # ... INFO TEST-START | /filepath/we/wish/to/capture.html\n
                 testStartFilenames = re.findall(r"TEST-START \| ([^\s]*)", currentlog)
                 if testStartFilenames:
                     self.lastTestSeen = testStartFilenames[-1]
                 if hasattr(self, 'logFinish') and self.logFinish in currentlog:
                     return 0
             else:
-                if time.time() > responseDueBy:
-                    self.log.info("TEST-UNEXPECTED-FAIL | %s | application timed "
-                                  "out after %d seconds with no output",
-                                  self.lastTestSeen, int(timeout))
-                    return 1
+                self.log.info("TEST-UNEXPECTED-FAIL | %s | application timed "
+                              "out after %d seconds with no output",
+                              self.lastTestSeen, int(timeout))
+                return 1
 
     def getDeviceStatus(self, serial=None):
         # Get the current status of the device.  If we know the device
         # serial number, we look for that, otherwise we use the (presumably
         # only) device shown in 'adb devices'.
         serial = serial or self._devicemanager.deviceSerial
         status = 'unknown'
 
@@ -331,26 +328,32 @@ class B2GRemoteAutomation(Automation):
             self.stdout_proc.waitForFinish()
             self.stdout_proc = None
 
         @property
         def pid(self):
             # a dummy value to make the automation happy
             return 0
 
-        @property
-        def stdout(self):
+        def getStdoutLines(self, timeout):
             # Return any lines in the queue used by the
             # b2g process handler.
             lines = []
+            # get all of the lines that are currently available
             while True:
                 try:
                     lines.append(self.queue.get_nowait())
                 except Queue.Empty:
                     break
+
+            # wait 'timeout' for any additional lines
+            try:
+                lines.append(self.queue.get(True, timeout))
+            except Queue.Empty:
+                pass
             return '\n'.join(lines)
 
         def wait(self, timeout=None):
             # this should never happen
             raise Exception("'wait' called on B2GInstance")
 
         def kill(self):
             # this should never happen