Skip to content

Commit

Permalink
Merge pull request #1180 from ashleysommer/fix_aiohttp_breakages
Browse files Browse the repository at this point in the history
Fix failing tests when aiohttp>=3.1.0
  • Loading branch information
r0fls authored Mar 29, 2018
2 parents 8a07463 + 94b9bc7 commit ef3bdf5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiofiles
aiohttp==1.3.5
aiohttp>=2.3.0
chardet<=2.3.0
beautifulsoup4
coverage
Expand Down
38 changes: 28 additions & 10 deletions tests/test_request_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,36 @@ async def delayed_send(self, *args, **kwargs):
t = req.loop.time()
print("sending at {}".format(t), flush=True)
conn = next(iter(args)) # first arg is connection
try:
delayed_resp = self.orig_send(*args, **kwargs)
except Exception as e:
return aiohttp.ClientResponse(req.method, req.url)
if aiohttp.__version__ >= "3.1.0":
try:
delayed_resp = await self.orig_send(*args, **kwargs)
except Exception as e:
return aiohttp.ClientResponse(req.method, req.url,
writer=None, continue100=None, timer=None,
request_info=None, auto_decompress=None, traces=[],
loop=req.loop, session=None)
else:
try:
delayed_resp = self.orig_send(*args, **kwargs)
except Exception as e:
return aiohttp.ClientResponse(req.method, req.url)
return delayed_resp

def send(self, *args, **kwargs):
gen = self.delayed_send(*args, **kwargs)
task = self.req.loop.create_task(gen)
self.send_task = task
self._acting_as = task
return self
if aiohttp.__version__ >= "3.1.0":
# aiohttp changed the request.send method to async
async def send(self, *args, **kwargs):
gen = self.delayed_send(*args, **kwargs)
task = self.req.loop.create_task(gen)
self.send_task = task
self._acting_as = task
return self
else:
def send(self, *args, **kwargs):
gen = self.delayed_send(*args, **kwargs)
task = self.req.loop.create_task(gen)
self.send_task = task
self._acting_as = task
return self

def __init__(self, *args, **kwargs):
_post_connect_delay = kwargs.pop('post_connect_delay', 0)
Expand Down

0 comments on commit ef3bdf5

Please sign in to comment.