Pylons/waitress — pull request #2 by dbaty (2012-10-24 22:29:55+00:00)
Title: Wait for all data to be sent before returning it

As Lorenzo Gil Sanchez [reported](https://groups.google.com/forum/?hl=fr&fromgroups=#!topic/pylons-devel/AFgtDJ9HsV4), tests in `test_functional.TestFileWrapper` may sometimes fail like this:

Traceback (most recent call last):
File "/home/damien/dev/waitress/waitress/tests/test_functional.py", line 1043, in test_filelike_longcl_http11
self.assertEqual(cl, len(response_body))
AssertionError: 45448 != 18000

I could reproduce these test failures on a rather low-end machine. They happen because the data is read from the socket before everything has been sent. The current implementation of `read_http()` tries to read N bytes; if less than N bytes have been sent at this point, the function returns nevertheless, not waiting for the rest of the data, hence the test failures.

The attached patch should work around this. (Note: this is a "bug" in the tests, not in the implementation.)