Skip to content

Commit

Permalink
[PR #9997/8c36b51 backport][3.11] Restore the force_close method …
Browse files Browse the repository at this point in the history
…to the ``ResponseHandler`` (#9998)
  • Loading branch information
bdraco authored Nov 19, 2024
1 parent 81c33ec commit b7e3b30
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/9997.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restored the ``force_close`` method to the ``ResponseHandler`` -- by :user:`bdraco`.
3 changes: 3 additions & 0 deletions aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def should_close(self) -> bool:
or self._tail
)

def force_close(self) -> None:
self._should_close = True

def close(self) -> None:
transport = self.transport
if transport is not None:
Expand Down
14 changes: 13 additions & 1 deletion tests/test_client_proto.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from unittest import mock

from yarl import URL
Expand All @@ -9,7 +10,18 @@
from aiohttp.helpers import TimerNoop


async def test_oserror(loop) -> None:
async def test_force_close(loop: asyncio.AbstractEventLoop) -> None:
"""Ensure that the force_close method sets the should_close attribute to True.
This is used externally in aiodocker
https://github.com/aio-libs/aiodocker/issues/920
"""
proto = ResponseHandler(loop=loop)
proto.force_close()
assert proto.should_close


async def test_oserror(loop: asyncio.AbstractEventLoop) -> None:
proto = ResponseHandler(loop=loop)
transport = mock.Mock()
proto.connection_made(transport)
Expand Down

0 comments on commit b7e3b30

Please sign in to comment.