Skip to content

Commit bdcf286

Browse files
authored
chore: fix test patching (#1292)
1 parent 461e6c1 commit bdcf286

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/zeroconf/_services/browser.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cdef class _DNSPointerOutgoingBucket:
2323

2424

2525
@cython.locals(answer=DNSPointer)
26-
cdef _group_ptr_queries_with_known_answers(object now, object multicast, cython.dict question_with_known_answers)
26+
cpdef _group_ptr_queries_with_known_answers(object now, object multicast, cython.dict question_with_known_answers)
2727

2828
cdef class QueryScheduler:
2929

tests/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from zeroconf import _core, _listener, const
11+
from zeroconf import _core, const
1212

1313

1414
@pytest.fixture(autouse=True)
@@ -34,7 +34,5 @@ def disable_duplicate_packet_suppression():
3434
Some tests run too slowly because of the duplicate
3535
packet suppression.
3636
"""
37-
with patch.object(_listener, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0), patch.object(
38-
const, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0
39-
):
37+
with patch.object(const, "_DUPLICATE_PACKET_SUPPRESSION_INTERVAL", 0):
4038
yield

tests/services/test_browser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
current_time_millis,
2727
millis_to_seconds,
2828
)
29-
from zeroconf._handlers import record_manager
3029
from zeroconf._services import ServiceStateChange
3130
from zeroconf._services.browser import ServiceBrowser
3231
from zeroconf._services.info import ServiceInfo
@@ -1159,7 +1158,6 @@ def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming:
11591158
zc.close()
11601159

11611160

1162-
@patch.object(record_manager, '_DNS_PTR_MIN_TTL', 1)
11631161
@patch.object(_engine, "_CACHE_CLEANUP_INTERVAL", 0.01)
11641162
def test_service_browser_expire_callbacks():
11651163
"""Test that the ServiceBrowser matching does not match partial names."""
@@ -1216,6 +1214,12 @@ def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming:
12161214
zc,
12171215
mock_incoming_msg([info.dns_pointer(), info.dns_service(), info.dns_text(), *info.dns_addresses()]),
12181216
)
1217+
# Force the ttl to be 1 second
1218+
now = current_time_millis()
1219+
for cache_record in zc.cache.cache.values():
1220+
for record in cache_record:
1221+
record.set_created_ttl(now, 1)
1222+
12191223
time.sleep(0.3)
12201224
info.port = 400
12211225
info._dns_service_cache = None # we are mutating the record so clear the cache

tests/test_handlers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,7 @@ async def test_response_aggregation_timings_multiple(run_isolated, disable_dupli
14951495
with unittest.mock.patch.object(aiozc.zeroconf, "async_send") as send_mock:
14961496
send_mock.reset_mock()
14971497
protocol.datagram_received(query2.packets()[0], ('127.0.0.1', const._MDNS_PORT))
1498+
protocol.last_time = 0 # manually reset the last time to avoid duplicate packet suppression
14981499
await asyncio.sleep(0.2)
14991500
calls = send_mock.mock_calls
15001501
assert len(calls) == 1
@@ -1505,6 +1506,7 @@ async def test_response_aggregation_timings_multiple(run_isolated, disable_dupli
15051506

15061507
send_mock.reset_mock()
15071508
protocol.datagram_received(query2.packets()[0], ('127.0.0.1', const._MDNS_PORT))
1509+
protocol.last_time = 0 # manually reset the last time to avoid duplicate packet suppression
15081510
await asyncio.sleep(1.2)
15091511
calls = send_mock.mock_calls
15101512
assert len(calls) == 1
@@ -1515,7 +1517,9 @@ async def test_response_aggregation_timings_multiple(run_isolated, disable_dupli
15151517

15161518
send_mock.reset_mock()
15171519
protocol.datagram_received(query2.packets()[0], ('127.0.0.1', const._MDNS_PORT))
1520+
protocol.last_time = 0 # manually reset the last time to avoid duplicate packet suppression
15181521
protocol.datagram_received(query2.packets()[0], ('127.0.0.1', const._MDNS_PORT))
1522+
protocol.last_time = 0 # manually reset the last time to avoid duplicate packet suppression
15191523
# The delay should increase with two packets and
15201524
# 900ms is beyond the maximum aggregation delay
15211525
# when there is no network protection delay

0 commit comments

Comments
 (0)