@@ -1071,6 +1071,13 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
10711071 # may finish before the first query fires, and answers[0] picks up
10721072 # the known PTR via RFC 6762 §7.1 known-answer suppression.
10731073 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 ()
10741081 got_query .clear ()
10751082 task = await aio_zeroconf_registrar .async_register_service (info )
10761083 await task
@@ -1090,7 +1097,9 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
10901097 got_query .clear ()
10911098 assert not unexpected_ttl .is_set ()
10921099
1093- 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
10941103 packets .clear ()
10951104
10961105 # Wait for the first refresh query
@@ -1104,12 +1113,12 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT, v6_flow_scope=()):
11041113 assert len (packets ) == 1
11051114 packets .clear ()
11061115
1107- assert len (answers ) == _services_browser .STARTUP_QUERIES + 1
1108- # The first question should have no known answers
1109- 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
11101119 # The rest of the startup questions should have
11111120 # known answers
1112- for answer_list in answers [1 :- 2 ]:
1121+ for answer_list in answers [:- 2 ]:
11131122 # Allow 0 or 1 answers due to random delays and timing
11141123 assert len (answer_list ) <= 1
11151124 # Once the TTL is reached, the last question should have no known answers
0 commit comments