Skip to content

Commit

Permalink
test for aio-libs#5156
Browse files Browse the repository at this point in the history
  • Loading branch information
derlih committed Oct 29, 2020
1 parent 48de143 commit 9d81913
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ async def fake_query_result(result):
return [FakeQueryResult(host=h) for h in result]


def fake_addrinfo(hosts):
def fake_addrinfo_raw(return_value):
async def fake(*args, **kwargs):
if not hosts:
if not return_value:
raise socket.gaierror

return list([(None, None, None, None, [h, 0]) for h in hosts])
return return_value

return fake


def fake_addrinfo(hosts):
return fake_addrinfo_raw(list([(None, None, None, None, [h, 0]) for h in hosts]))


@pytest.mark.skipif(not gethostbyname, reason="aiodns 1.1 required")
async def test_async_resolver_positive_lookup(loop) -> None:
with patch("aiodns.DNSResolver") as mock:
Expand Down Expand Up @@ -160,3 +164,17 @@ def test_default_resolver() -> None:
# else:
# assert DefaultResolver is ThreadedResolver
assert DefaultResolver is ThreadedResolver


async def test_threaded_resolver_5156() -> None:
loop = Mock()
loop.getaddrinfo = fake_addrinfo_raw(
[
(2, 1, 6, "", ("151.101.188.223", 443)),
(10, 1, 6, "", (10, b"\x01\xbb\x00\x00\x00\x00*\x04NB\x00-\x00\x00")),
]
)
resolver = ThreadedResolver()
resolver._loop = loop

await resolver.resolve("foo")

0 comments on commit 9d81913

Please sign in to comment.