Skip to content

Commit 82d8c27

Browse files
committed
improve aiodns and aiohttp and apply smarter shutdown logic to BaseTestCase
1 parent 6b031ac commit 82d8c27

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

tests/test_aiodns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
class _TestAiodns:
2020
def test_dns_query(self):
2121
# This is not allowed to fail...
22-
resolver = aiodns.DNSResolver(loop=self.loop)
22+
resolver = aiodns.DNSResolver(["8.8.8.8", "8.8.4.4"], loop=self.loop)
2323

2424
async def test():
2525
async def query(name, query_type):
26-
return await resolver.query(name, query_type)
26+
return await resolver.query_dns(name, query_type)
2727

2828
await query("google.com", "A")
2929
await query("httpbin.org", "A")

tests/test_aiohttp.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import asyncio
1010
import sys
1111
import unittest
12+
import warnings # Needed for suppressing aiohttp NotAppKeyWarning (temporary patch)
1213
import weakref
1314

1415
from winloop import _testbase as tb
@@ -78,16 +79,20 @@ async def on_shutdown(app):
7879
app = aiohttp.web.Application()
7980
app.router.add_get("/", websocket_handler)
8081
app.on_shutdown.append(on_shutdown)
81-
app["websockets"] = weakref.WeakSet()
82+
83+
with warnings.catch_warnings():
84+
# Just filter it for now. A workaround will be utilized in the future...
85+
warnings.filterwarnings("ignore", category=aiohttp.web.NotAppKeyWarning)
86+
app["websockets"] = weakref.WeakSet()
8287

83-
runner = aiohttp.web.AppRunner(app)
88+
runner = aiohttp.web.AppRunner(app, shutdown_timeout=0.1)
8489
self.loop.run_until_complete(runner.setup())
8590
site = aiohttp.web.TCPSite(
8691
runner,
8792
"0.0.0.0",
8893
0,
8994
# https://github.com/aio-libs/aiohttp/pull/7188
90-
shutdown_timeout=0.1,
95+
# shutdown_timeout=0.1,
9196
)
9297
self.loop.run_until_complete(site.start())
9398
port = site._server.sockets[0].getsockname()[1]

winloop/_testbase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def setUp(self):
101101
self.__unhandled_exceptions = []
102102

103103
def tearDown(self):
104-
self.loop.close()
104+
if self.loop.is_closed:
105+
self.loop.close()
105106

106107
if self.__unhandled_exceptions:
107108
print("Unexpected calls to loop.call_exception_handler():")
@@ -329,7 +330,6 @@ def setUp(self):
329330
def tearDown(self):
330331
if sys.platform != "win32" and sys.version_info < (3, 12):
331332
asyncio.set_child_watcher(None)
332-
super().tearDown()
333333

334334
def new_loop(self):
335335
return asyncio.new_event_loop()

0 commit comments

Comments
 (0)