Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 2458

Show
Ignore:
Timestamp:
06/16/09 11:02:43
Author:
fumanchu
Message:

python3: made test_file_stream/test_deadlock more stable.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/python3/cherrypy/test/test_static.py

    r2438 r2458  
    22test.prefer_parent_path() 
    33 
     4import http.client 
    45from io import BytesIO 
    56 
     
    3031         
    3132        def tell(self): 
     33            if self.f.input.closed: 
     34                return '' 
    3235            return repr(self.f.input.tell()) 
    3336        tell.exposed = True 
     
    225228        self.assertEqual(response.status, 200) 
    226229         
    227         body = '' 
     230        body = b'' 
    228231        remaining = BIGFILE_SIZE 
    229         # By this point, the webserver has already written one chunk to 
    230         # the socket and queued another. So we start with i=1. 
    231         i = 1 
    232232        while remaining > 0: 
    233             i += 1 
    234             s, h, b = helper.webtest.openURL( 
    235                 b"/tell", headers=[], host=self.HOST, port=self.PORT) 
    236             if remaining != 65536: 
    237                 self.assertEqual(int(b), 65536 * i) 
    238233            data = response.fp.read(65536) 
    239234            if not data: 
     
    241236            body += data 
    242237            remaining -= len(data) 
    243          
    244         if body != "x" * BIGFILE_SIZE: 
     238             
     239            if self.scheme == "https": 
     240                newconn = http.client.HTTPSConnection 
     241            else: 
     242                newconn = http.client.HTTPConnection 
     243            s, h, b = helper.webtest.openURL( 
     244                b"/tell", headers=[], host=self.HOST, port=self.PORT, 
     245                http_conn=newconn) 
     246            if not b: 
     247                # The file was closed on the server. 
     248                tell_position = BIGFILE_SIZE 
     249            else: 
     250                tell_position = int(b) 
     251             
     252            expected = len(body) 
     253            if tell_position >= BIGFILE_SIZE: 
     254                # We can't exactly control how much content the server asks for. 
     255                # Fudge it by only checking the first half of the reads. 
     256                if expected < (BIGFILE_SIZE / 2): 
     257                    self.fail( 
     258                        "The file should have advanced to position %r, but has " 
     259                        "already advanced to the end of the file. It may not be " 
     260                        "streamed as intended, or at the wrong chunk size (64k)" % 
     261                        expected) 
     262            elif tell_position < expected: 
     263                self.fail( 
     264                    "The file should have advanced to position %r, but has " 
     265                    "only advanced to position %r. It may not be streamed " 
     266                    "as intended, or at the wrong chunk size (65536)" % 
     267                    (expected, tell_position)) 
     268         
     269        if body != b"x" * BIGFILE_SIZE: 
    245270            self.fail("Body != 'x' * %d. Got %r instead (%d bytes)." % 
    246271                      (BIGFILE_SIZE, body[:50], len(body))) 
     
    263288        self.assertEqual(response.status, 200) 
    264289        body = response.fp.read(65536) 
    265         if body != b"x" * 65536
     290        if body != b"x" * len(body)
    266291            self.fail("Body != b'x' * %d. Got %r instead (%d bytes)." % 
    267292                      (65536, body[:50], len(body))) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets