From b123420a8735afa5a98e308b0a1c9f39695c9f81 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Nov 2023 07:51:20 -0600 Subject: [PATCH 1/8] Bump aiohttp to 3.9.0b1 for python 3.12 only changelog: https://github.com/aio-libs/aiohttp/compare/v3.9.0b0...v3.9.0b1 This should fix all the known issues we had with b0 --- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 2c38dc8f153e32..8ebb03204e4e4b 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -1,7 +1,7 @@ aiodiscover==1.5.1 aiohttp-zlib-ng==0.1.1 aiohttp==3.8.5;python_version<'3.12' -aiohttp==3.9.0b0;python_version>='3.12' +aiohttp==3.9.0b1;python_version>='3.12' aiohttp_cors==0.7.0 astral==2.2 async-upnp-client==0.36.2 diff --git a/pyproject.toml b/pyproject.toml index 60557c3948e82e..93b461d9bf262e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ ] requires-python = ">=3.11.0" dependencies = [ - "aiohttp==3.9.0b0;python_version>='3.12'", + "aiohttp==3.9.0b1;python_version>='3.12'", "aiohttp==3.8.5;python_version<'3.12'", "aiohttp_cors==0.7.0", "aiohttp-zlib-ng==0.1.1", diff --git a/requirements.txt b/requirements.txt index 98d6e3864e2500..33bf5d5729005c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -c homeassistant/package_constraints.txt # Home Assistant Core -aiohttp==3.9.0b0;python_version>='3.12' +aiohttp==3.9.0b1;python_version>='3.12' aiohttp==3.8.5;python_version<'3.12' aiohttp_cors==0.7.0 aiohttp-zlib-ng==0.1.1 From 2dcb31fc594fd003bf937b980e1d522b7b8ba556 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Nov 2023 17:17:45 -0600 Subject: [PATCH 2/8] fix mocking --- tests/test_util/aiohttp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index 356240dc37a168..8b7162fab69620 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -149,6 +149,10 @@ async def match_request( raise AssertionError(f"No mock registered for {method.upper()} {url} {params}") + async def wait_for_close(self): + """Wait until all requests are done.""" + await asyncio.sleep(0) + class AiohttpClientMockResponse: """Mock Aiohttp client response.""" From 1e9313e6c953b401aedacf9d8eb7c290bf0e1ced Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Nov 2023 17:18:31 -0600 Subject: [PATCH 3/8] fix mocking --- tests/test_util/aiohttp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index 8b7162fab69620..9d83cdc914082d 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -150,7 +150,11 @@ async def match_request( raise AssertionError(f"No mock registered for {method.upper()} {url} {params}") async def wait_for_close(self): - """Wait until all requests are done.""" + """Wait until all requests are done. + + For the purposes of mocking, we only need to run + the event loop once to let the request finish. + """ await asyncio.sleep(0) From 059a22e1eeb38b2536ba7b6fd1f220264add191b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Nov 2023 18:24:10 -0600 Subject: [PATCH 4/8] wrong class --- tests/test_util/aiohttp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index 9d83cdc914082d..f91f722eb4d41f 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -149,14 +149,6 @@ async def match_request( raise AssertionError(f"No mock registered for {method.upper()} {url} {params}") - async def wait_for_close(self): - """Wait until all requests are done. - - For the purposes of mocking, we only need to run - the event loop once to let the request finish. - """ - await asyncio.sleep(0) - class AiohttpClientMockResponse: """Mock Aiohttp client response.""" @@ -280,6 +272,14 @@ def raise_for_status(self): def close(self): """Mock close.""" + async def wait_for_close(self): + """Wait until all requests are done. + + For the purposes of mocking, we only need to run + the event loop once to let the request finish. + """ + await asyncio.sleep(0) + @contextmanager def mock_aiohttp_client(): From 4e00ff5613e89574005309e791710711e259650e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Nov 2023 08:37:56 -0600 Subject: [PATCH 5/8] fix race in unifi test --- tests/components/unifi/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/unifi/conftest.py b/tests/components/unifi/conftest.py index d48ff6139026c6..4252bdc626d06c 100644 --- a/tests/components/unifi/conftest.py +++ b/tests/components/unifi/conftest.py @@ -55,7 +55,7 @@ async def reconnect(self, fail=False): if not fail: self.clear() - new_time = dt_util.utcnow() + timedelta(seconds=RETRY_TIMER) + new_time = dt_util.utcnow() + timedelta(seconds=RETRY_TIMER * 2) async_fire_time_changed(self.hass, new_time) await self.hass.async_block_till_done() From 7786ed1b9e98619433852eb588e5538a68175f07 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Nov 2023 08:39:34 -0600 Subject: [PATCH 6/8] keep test compat --- tests/components/unifi/conftest.py | 2 +- tests/test_util/aiohttp.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/components/unifi/conftest.py b/tests/components/unifi/conftest.py index 4252bdc626d06c..d48ff6139026c6 100644 --- a/tests/components/unifi/conftest.py +++ b/tests/components/unifi/conftest.py @@ -55,7 +55,7 @@ async def reconnect(self, fail=False): if not fail: self.clear() - new_time = dt_util.utcnow() + timedelta(seconds=RETRY_TIMER * 2) + new_time = dt_util.utcnow() + timedelta(seconds=RETRY_TIMER) async_fire_time_changed(self.hass, new_time) await self.hass.async_block_till_done() diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index f91f722eb4d41f..918e9132de84a7 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -275,10 +275,8 @@ def close(self): async def wait_for_close(self): """Wait until all requests are done. - For the purposes of mocking, we only need to run - the event loop once to let the request finish. + Do nothing as we are mocking. """ - await asyncio.sleep(0) @contextmanager From 211bdf3edc0e361eb02ccbb3bb074dc5316b94dd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 14 Nov 2023 15:16:32 -0600 Subject: [PATCH 7/8] bump to rc0 --- homeassistant/helpers/aiohttp_client.py | 13 ------------- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index b8d810d899b7b8..fba9bb647ddd53 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -58,19 +58,6 @@ MAXIMUM_CONNECTIONS_PER_HOST = 100 -# Overwrite base aiohttp _wait implementation -# Homeassistant has a custom shutdown wait logic. -async def _noop_wait(*args: Any, **kwargs: Any) -> None: - """Do nothing.""" - return - - -# TODO: Remove version check with aiohttp 3.9.0 # pylint: disable=fixme -if sys.version_info >= (3, 12): - # pylint: disable-next=protected-access - web.BaseSite._wait = _noop_wait # type: ignore[method-assign] - - class HassClientResponse(aiohttp.ClientResponse): """aiohttp.ClientResponse with a json method that uses json_loads by default.""" diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index fd288b93dcce08..6c21478105b4fc 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -1,7 +1,7 @@ aiodiscover==1.5.1 aiohttp-zlib-ng==0.1.1 aiohttp==3.8.5;python_version<'3.12' -aiohttp==3.9.0b1;python_version>='3.12' +aiohttp==3.9.0rc0;python_version>='3.12' aiohttp_cors==0.7.0 astral==2.2 async-upnp-client==0.36.2 diff --git a/pyproject.toml b/pyproject.toml index 93b461d9bf262e..a668498ffe546e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ ] requires-python = ">=3.11.0" dependencies = [ - "aiohttp==3.9.0b1;python_version>='3.12'", + "aiohttp==3.9.0rc0;python_version>='3.12'", "aiohttp==3.8.5;python_version<'3.12'", "aiohttp_cors==0.7.0", "aiohttp-zlib-ng==0.1.1", diff --git a/requirements.txt b/requirements.txt index 33bf5d5729005c..dd74587c075e02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -c homeassistant/package_constraints.txt # Home Assistant Core -aiohttp==3.9.0b1;python_version>='3.12' +aiohttp==3.9.0rc0;python_version>='3.12' aiohttp==3.8.5;python_version<'3.12' aiohttp_cors==0.7.0 aiohttp-zlib-ng==0.1.1 From 8160bfc6e871bc6f445d314fab465eafc25b3e4f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 14 Nov 2023 15:18:45 -0600 Subject: [PATCH 8/8] lint --- tests/test_util/aiohttp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index c2237aebc00bb0..4f2518253ffa1d 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -285,6 +285,7 @@ async def wait_for_close(self): Do nothing as we are mocking. """ + @property def response(self): """Property method to expose the response to other read methods."""