Make it easier to debug badly broken tests.

If you manage to break a proxy server so badly that it can't even
return headers, then in test/unit/proxy/test_server.py,
readuntil2crlfs() will spin forever, killing your laptop battery and
providing zero help figuring out what's wrong.

This test-only change makes it so that, should readuntil2crlfs() run
out of data before getting its two CRLFs, it raises an exception that
tells you what it did manage to get, and does so in a finite amount of
time.

Change-Id: Ieacd18ce7f4d35a4960100d5fc3a0f910cb406ac
This commit is contained in:
Samuel Merritt 2013-04-24 14:01:56 -07:00
parent 5d52d2d1cc
commit 813f7c9de6

View File

@ -24,6 +24,8 @@ def readuntil2crlfs(fd):
crlfs = 0
while crlfs < 2:
c = fd.read(1)
if not c:
raise ValueError("didn't get two CRLFs; just got %r" % rv)
rv = rv + c
if c == '\r' and lc != '\n':
crlfs = 0