Title: [94973] trunk/Tools
Revision
94973
Author
e...@webkit.org
Date
2011-09-12 13:06:40 -0700 (Mon, 12 Sep 2011)

Log Message

Reshuffle some code in WebKitDriver._read_block in preparation for reading stderr/stdout separately
https://bugs.webkit.org/show_bug.cgi?id=67530

Reviewed by Adam Barth.

I believe I've fixed the bug in the original patch which prompted the rollout.
The previous patch was using the wrong deadline for the initial read,
subtracting time.time() twice from the deadline value.

* Scripts/webkitpy/layout_tests/port/webkit.py:
* Scripts/webkitpy/layout_tests/port/webkit_unittest.py:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (94972 => 94973)


--- trunk/Tools/ChangeLog	2011-09-12 20:05:52 UTC (rev 94972)
+++ trunk/Tools/ChangeLog	2011-09-12 20:06:40 UTC (rev 94973)
@@ -1,3 +1,17 @@
+2011-09-12  Eric Seidel  <e...@webkit.org>
+
+        Reshuffle some code in WebKitDriver._read_block in preparation for reading stderr/stdout separately
+        https://bugs.webkit.org/show_bug.cgi?id=67530
+
+        Reviewed by Adam Barth.
+
+        I believe I've fixed the bug in the original patch which prompted the rollout.
+        The previous patch was using the wrong deadline for the initial read,
+        subtracting time.time() twice from the deadline value.
+
+        * Scripts/webkitpy/layout_tests/port/webkit.py:
+        * Scripts/webkitpy/layout_tests/port/webkit_unittest.py:
+
 2011-09-12  Balazs Kelemen  <kbal...@webkit.org>
 
         [Qt][WK2] WebKitTestRunner does not produce crash logs

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py (94972 => 94973)


--- trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py	2011-09-12 20:05:52 UTC (rev 94972)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py	2011-09-12 20:06:40 UTC (rev 94973)
@@ -509,44 +509,46 @@
             crash=self.detected_crash(), test_time=time.time() - start_time,
             timeout=self._server_process.timed_out, error=error)
 
+    LENGTH_HEADER = 'Content-Length: '
+    HASH_HEADER = 'ActualHash: '
+    TYPE_HEADER = 'Content-Type: '
+    ENCODING_HEADER = 'Content-Transfer-Encoding: '
+
+    def _read_line_until(self, deadline):
+        return self._server_process.read_line(deadline - time.time())
+
     def _read_block(self, deadline):
-        LENGTH_HEADER = 'Content-Length: '
-        HASH_HEADER = 'ActualHash: '
-        TYPE_HEADER = 'Content-Type: '
-        ENCODING_HEADER = 'Content-Transfer-Encoding: '
         content_type = None
         encoding = None
         content_hash = None
         content_length = None
 
         # Content is treated as binary data even though the text output is usually UTF-8.
-        content = ''
-        timeout = deadline - time.time()
-        line = self._server_process.read_line(timeout)
+        content = str()  # FIXME: Should be bytearray() once we require Python 2.6.
+        line = self._read_line_until(deadline)
         eof = False
         while (not self._server_process.timed_out and not self.detected_crash() and not eof):
-            chomped_line = line.rstrip()
+            chomped_line = line.rstrip()  # FIXME: This will remove trailing lines from test output.  Is that right?
             if chomped_line.endswith("#EOF"):
                 eof = True
                 line = chomped_line[:-4]
 
-            if line.startswith(TYPE_HEADER) and content_type is None:
+            if line.startswith(self.TYPE_HEADER) and content_type is None:
                 content_type = line.split()[1]
-            elif line.startswith(ENCODING_HEADER) and encoding is None:
+            elif line.startswith(self.ENCODING_HEADER) and encoding is None:
                 encoding = line.split()[1]
-            elif line.startswith(LENGTH_HEADER) and content_length is None:
-                timeout = deadline - time.time()
-                content_length = int(line[len(LENGTH_HEADER):])
-                # FIXME: Technically there should probably be another blank
-                # line here, but DRT doesn't write one.
-                content = self._server_process.read(timeout, content_length)
-            elif line.startswith(HASH_HEADER):
+            elif line.startswith(self.LENGTH_HEADER) and content_length is None:
+                content_length = int(line[len(self.LENGTH_HEADER):])
+                # FIXME: In real HTTP there should probably be a blank line
+                # after headers before content, but DRT doesn't write one.
+                content = self._server_process.read(deadline - time.time(), content_length)
+            elif line.startswith(self.HASH_HEADER):
                 content_hash = line.split()[1]
             elif line:
                 content += line
-            if not eof:
-                line = self._server_process.read_line(timeout)
-                timeout = deadline - time.time()
+            if eof:
+                break
+            line = self._read_line_until(deadline)
         return ContentBlock(content_type, encoding, content_hash, content)
 
     def stop(self):

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py (94972 => 94973)


--- trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py	2011-09-12 20:05:52 UTC (rev 94972)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py	2011-09-12 20:06:40 UTC (rev 94973)
@@ -31,7 +31,7 @@
 from webkitpy.common.system.outputcapture import OutputCapture
 
 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
-from webkitpy.layout_tests.port.webkit import WebKitPort
+from webkitpy.layout_tests.port.webkit import WebKitPort, WebKitDriver
 from webkitpy.layout_tests.port import port_testcase
 
 from webkitpy.tool.mocktool import MockExecutive, MockOptions, MockUser
@@ -197,3 +197,29 @@
         # Mock out _apache_config_file_name_for_platform to ignore the passed sys.platform value.
         port._apache_config_file_name_for_platform = lambda platform: 'httpd.conf'
         self.assertEquals(port._path_to_apache_config_file(), '/mock-checkout/LayoutTests/http/conf/httpd.conf')
+
+
+class MockServerProcess(object):
+    def __init__(self, lines=None):
+        self.timed_out = False
+        self.crashed = False
+        self.lines = lines or []
+
+    def read_line(self, timeout):
+        return self.lines.pop(0)
+
+
+class WebKitDriverTest(unittest.TestCase):
+    def test_read_block(self):
+        port = TestWebKitPort()
+        driver = WebKitDriver(port, 0)
+        driver._server_process = MockServerProcess([
+            'ActualHash: foobar',
+            'Content-Type: my_type',
+            'Content-Transfer-Encoding: none',
+            "#EOF",
+        ])
+        content_block = driver._read_block(0)
+        self.assertEquals(content_block.content_type, 'my_type')
+        self.assertEquals(content_block.encoding, 'none')
+        self.assertEquals(content_block.content_hash, 'foobar')
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to