Skip to content

Commit d40f913

Browse files
authored
Add Winloop as a valid EventLoop (#116)
* add winloop as a valid event loop * add uvloop and winloop for testing * Update tests.py
1 parent ca7b018 commit d40f913

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

aiodns/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,14 @@ def __init__(self, nameservers: Optional[Sequence[str]] = None,
5252
assert self.loop is not None
5353
if sys.platform == 'win32':
5454
if not isinstance(self.loop, asyncio.SelectorEventLoop):
55-
raise RuntimeError(
56-
'aiodns needs a SelectorEventLoop on Windows. See more: https://github.com/saghul/aiodns/issues/86')
55+
try:
56+
import winloop
57+
if not isinstance(self.loop , winloop.Loop):
58+
raise RuntimeError(
59+
'aiodns needs a SelectorEventLoop on Windows. See more: https://github.com/saghul/aiodns/issues/86')
60+
except ModuleNotFoundError:
61+
raise RuntimeError(
62+
'aiodns needs a SelectorEventLoop on Windows. See more: https://github.com/saghul/aiodns/issues/86')
5763
kwargs.pop('sock_state_cb', None)
5864
timeout = kwargs.pop('timeout', None)
5965
self._timeout = timeout

tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
import aiodns
1111

12+
try:
13+
if sys.platform == "win32":
14+
import winloop as uvloop
15+
skip_uvloop = False
16+
else:
17+
import uvloop
18+
skip_uvloop = False
19+
except ModuleNotFoundError:
20+
skip_uvloop = True
21+
1222

1323
class DNSTest(unittest.TestCase):
1424
def setUp(self):
@@ -162,6 +172,14 @@ def test_gethostbyname_bad_family(self):
162172
# result = self.loop.run_until_complete(f)
163173
# self.assertTrue(result)
164174

175+
@unittest.skipIf(skip_uvloop, "We don't have a uvloop or winloop module")
176+
class TestUV_DNS(DNSTest):
177+
def setUp(self):
178+
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
179+
self.loop = asyncio.new_event_loop()
180+
self.addCleanup(self.loop.close)
181+
self.resolver = aiodns.DNSResolver(loop=self.loop, timeout=5.0)
182+
self.resolver.nameservers = ['8.8.8.8']
165183

166184
if __name__ == '__main__':
167185
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)