Skip to content

Commit

Permalink
http.client: Handle and warn incomplete sessions instead of assert.
Browse files Browse the repository at this point in the history
Closes #177
  • Loading branch information
chfoo committed Feb 17, 2015
1 parent 2e4f5b5 commit 20e051a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion wpull/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import gettext
import logging
import warnings

from trollius import From, Return
import trollius
Expand Down Expand Up @@ -157,7 +158,10 @@ def abort(self):
self._session_complete = True

def recycle(self):
assert self._session_complete
if not self._session_complete:
warnings.warn(_('HTTP session did not complete.'))

self.abort()

if self._connection:
self._connection_pool.check_in(self._connection)
9 changes: 7 additions & 2 deletions wpull/http/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import contextlib
import functools
import io
import warnings

from trollius import From

Expand Down Expand Up @@ -137,15 +138,19 @@ def test_client_recorder(self):
self.assertIn(b'hello', recorder.response_data)

@wpull.testing.async.async_test(timeout=DEFAULT_TIMEOUT)
def test_client_exception_close(self):
def test_client_did_not_complete(self):
client = Client()

with self.assertRaises(AssertionError):
with warnings.catch_warnings(record=True) as warn_list:
warnings.simplefilter("always")

with client.session() as session:
request = Request(self.get_url('/'))
response = yield From(session.fetch(request))
self.assertFalse(session.done())

self.assertEqual(1, len(warn_list))

client = Client()

with self.assertRaises(MyException):
Expand Down

0 comments on commit 20e051a

Please sign in to comment.