Skip to content

fix: correctly override question type flag for requests #1558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/zeroconf/_services/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ async def async_request(
if last <= now:
return False
if next_ <= now:
this_question_type = question_type or QU_QUESTION if first_request else QM_QUESTION
this_question_type = question_type or (QU_QUESTION if first_request else QM_QUESTION)
out = self._generate_request_query(zc, now, this_question_type)
first_request = False
if out.questions:
Expand Down
21 changes: 21 additions & 0 deletions tests/services/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import zeroconf as r
from zeroconf import DNSAddress, RecordUpdate, const
from zeroconf._protocol.outgoing import DNSOutgoing
from zeroconf._services import info
from zeroconf._services.info import ServiceInfo
from zeroconf._utils.net import IPVersion
Expand Down Expand Up @@ -1871,3 +1872,23 @@ async def test_address_resolver_ipv6():
aiozc.zeroconf.async_send(outgoing)
assert await resolve_task
assert resolver.ip_addresses_by_version(IPVersion.All) == [ip_address("fe80::52e:c2f2:bc5f:e9c6")]


@pytest.mark.asyncio
async def test_unicast_flag_if_requested() -> None:
"""Verify we try four times even with the random delay."""
type_ = "_typethatisnothere._tcp.local."
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])

def async_send(out: DNSOutgoing, addr: str | None = None, port: int = const._MDNS_PORT) -> None:
"""Sends an outgoing packet."""
for question in out.questions:
assert question.unicast

# patch the zeroconf send
with patch.object(aiozc.zeroconf, "async_send", async_send):
await aiozc.async_get_service_info(
f"willnotbefound.{type_}", type_, question_type=r.DNSQuestionType.QU
)

await aiozc.async_close()
Loading