Changeset 94973 in webkit


Ignore:
Timestamp:
Sep 12, 2011 1:06:40 PM (13 years ago)
Author:
eric@webkit.org
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:
Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r94956 r94973  
     12011-09-12  Eric Seidel  <eric@webkit.org>
     2
     3        Reshuffle some code in WebKitDriver._read_block in preparation for reading stderr/stdout separately
     4        https://bugs.webkit.org/show_bug.cgi?id=67530
     5
     6        Reviewed by Adam Barth.
     7
     8        I believe I've fixed the bug in the original patch which prompted the rollout.
     9        The previous patch was using the wrong deadline for the initial read,
     10        subtracting time.time() twice from the deadline value.
     11
     12        * Scripts/webkitpy/layout_tests/port/webkit.py:
     13        * Scripts/webkitpy/layout_tests/port/webkit_unittest.py:
     14
    1152011-09-12  Balazs Kelemen  <kbalazs@webkit.org>
    216
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit.py

    r94483 r94973  
    510510            timeout=self._server_process.timed_out, error=error)
    511511
     512    LENGTH_HEADER = 'Content-Length: '
     513    HASH_HEADER = 'ActualHash: '
     514    TYPE_HEADER = 'Content-Type: '
     515    ENCODING_HEADER = 'Content-Transfer-Encoding: '
     516
     517    def _read_line_until(self, deadline):
     518        return self._server_process.read_line(deadline - time.time())
     519
    512520    def _read_block(self, deadline):
    513         LENGTH_HEADER = 'Content-Length: '
    514         HASH_HEADER = 'ActualHash: '
    515         TYPE_HEADER = 'Content-Type: '
    516         ENCODING_HEADER = 'Content-Transfer-Encoding: '
    517521        content_type = None
    518522        encoding = None
     
    521525
    522526        # Content is treated as binary data even though the text output is usually UTF-8.
    523         content = ''
    524         timeout = deadline - time.time()
    525         line = self._server_process.read_line(timeout)
     527        content = str()  # FIXME: Should be bytearray() once we require Python 2.6.
     528        line = self._read_line_until(deadline)
    526529        eof = False
    527530        while (not self._server_process.timed_out and not self.detected_crash() and not eof):
    528             chomped_line = line.rstrip()
     531            chomped_line = line.rstrip()  # FIXME: This will remove trailing lines from test output.  Is that right?
    529532            if chomped_line.endswith("#EOF"):
    530533                eof = True
    531534                line = chomped_line[:-4]
    532535
    533             if line.startswith(TYPE_HEADER) and content_type is None:
     536            if line.startswith(self.TYPE_HEADER) and content_type is None:
    534537                content_type = line.split()[1]
    535             elif line.startswith(ENCODING_HEADER) and encoding is None:
     538            elif line.startswith(self.ENCODING_HEADER) and encoding is None:
    536539                encoding = line.split()[1]
    537             elif line.startswith(LENGTH_HEADER) and content_length is None:
    538                 timeout = deadline - time.time()
    539                 content_length = int(line[len(LENGTH_HEADER):])
    540                 # FIXME: Technically there should probably be another blank
    541                 # line here, but DRT doesn't write one.
    542                 content = self._server_process.read(timeout, content_length)
    543             elif line.startswith(HASH_HEADER):
     540            elif line.startswith(self.LENGTH_HEADER) and content_length is None:
     541                content_length = int(line[len(self.LENGTH_HEADER):])
     542                # FIXME: In real HTTP there should probably be a blank line
     543                # after headers before content, but DRT doesn't write one.
     544                content = self._server_process.read(deadline - time.time(), content_length)
     545            elif line.startswith(self.HASH_HEADER):
    544546                content_hash = line.split()[1]
    545547            elif line:
    546548                content += line
    547             if not eof:
    548                 line = self._server_process.read_line(timeout)
    549                 timeout = deadline - time.time()
     549            if eof:
     550                break
     551            line = self._read_line_until(deadline)
    550552        return ContentBlock(content_type, encoding, content_hash, content)
    551553
  • trunk/Tools/Scripts/webkitpy/layout_tests/port/webkit_unittest.py

    r94483 r94973  
    3232
    3333from webkitpy.layout_tests.models.test_configuration import TestConfiguration
    34 from webkitpy.layout_tests.port.webkit import WebKitPort
     34from webkitpy.layout_tests.port.webkit import WebKitPort, WebKitDriver
    3535from webkitpy.layout_tests.port import port_testcase
    3636
     
    198198        port._apache_config_file_name_for_platform = lambda platform: 'httpd.conf'
    199199        self.assertEquals(port._path_to_apache_config_file(), '/mock-checkout/LayoutTests/http/conf/httpd.conf')
     200
     201
     202class MockServerProcess(object):
     203    def __init__(self, lines=None):
     204        self.timed_out = False
     205        self.crashed = False
     206        self.lines = lines or []
     207
     208    def read_line(self, timeout):
     209        return self.lines.pop(0)
     210
     211
     212class WebKitDriverTest(unittest.TestCase):
     213    def test_read_block(self):
     214        port = TestWebKitPort()
     215        driver = WebKitDriver(port, 0)
     216        driver._server_process = MockServerProcess([
     217            'ActualHash: foobar',
     218            'Content-Type: my_type',
     219            'Content-Transfer-Encoding: none',
     220            "#EOF",
     221        ])
     222        content_block = driver._read_block(0)
     223        self.assertEquals(content_block.content_type, 'my_type')
     224        self.assertEquals(content_block.encoding, 'none')
     225        self.assertEquals(content_block.content_hash, 'foobar')
Note: See TracChangeset for help on using the changeset viewer.