Skip to content

Commit cb81e67

Browse files
authored
test: synchronise test_integration on browser first-query (#1771)
1 parent 78670f7 commit cb81e67

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

tests/test_asyncio.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,19 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
10661066
"ash-2.local.",
10671067
addresses=[socket.inet_aton("10.0.1.2")],
10681068
)
1069+
# Wait for the browser's first startup query to land (with an empty
1070+
# cache) before registering — otherwise on fast loopback the register
1071+
# may finish before the first query fires, and answers[0] picks up
1072+
# the known PTR via RFC 6762 §7.1 known-answer suppression.
1073+
await asyncio.wait_for(got_query.wait(), 1)
1074+
# Snapshot the first query's answers and reset the captures so the
1075+
# subsequent assertions don't have to predict whether further startup
1076+
# queries fire in real time (before the manual time_changed_millis
1077+
# loop) or under mock time.
1078+
first_answers = answers[0]
1079+
packets.clear()
1080+
answers.clear()
1081+
got_query.clear()
10691082
task = await aio_zeroconf_registrar.async_register_service(info)
10701083
await task
10711084
loop = asyncio.get_running_loop()
@@ -1084,7 +1097,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
10841097
got_query.clear()
10851098
assert not unexpected_ttl.is_set()
10861099

1087-
assert len(packets) == _services_browser.STARTUP_QUERIES
1100+
# The first startup query was captured separately, so only the
1101+
# remaining STARTUP_QUERIES - 1 land here.
1102+
assert len(packets) == _services_browser.STARTUP_QUERIES - 1
10881103
packets.clear()
10891104

10901105
# Wait for the first refresh query
@@ -1098,12 +1113,12 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
10981113
assert len(packets) == 1
10991114
packets.clear()
11001115

1101-
assert len(answers) == _services_browser.STARTUP_QUERIES + 1
1102-
# The first question should have no known answers
1103-
assert len(answers[0]) == 0
1116+
assert len(answers) == _services_browser.STARTUP_QUERIES
1117+
# The first question (captured separately) should have no known answers
1118+
assert len(first_answers) == 0
11041119
# The rest of the startup questions should have
11051120
# known answers
1106-
for answer_list in answers[1:-2]:
1121+
for answer_list in answers[:-2]:
11071122
# Allow 0 or 1 answers due to random delays and timing
11081123
assert len(answer_list) <= 1
11091124
# Once the TTL is reached, the last question should have no known answers

0 commit comments

Comments
 (0)