Skip to content

Commit 94a183c

Browse files
committed
Merge branch 'cython_signal_interface' into decode_labels_incoming_speed_up
2 parents cc8fb1e + eb3e2c6 commit 94a183c

7 files changed

Lines changed: 27 additions & 8 deletions

File tree

build_ext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def build(setup_kwargs: Any) -> None:
3333
"src/zeroconf/_handlers/record_manager.py",
3434
"src/zeroconf/_handlers/multicast_outgoing_queue.py",
3535
"src/zeroconf/_handlers/query_handler.py",
36+
"src/zeroconf/_services/__init__.py",
3637
"src/zeroconf/_services/browser.py",
3738
"src/zeroconf/_services/info.py",
3839
"src/zeroconf/_services/registry.py",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import cython
3+
4+
5+
cdef class Signal:
6+
7+
cdef list _handlers
8+
9+
cdef class SignalRegistrationInterface:
10+
11+
cdef list _handlers

src/zeroconf/_services/browser.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from .._cache cimport DNSCache
55
from .._protocol.outgoing cimport DNSOutgoing, DNSPointer, DNSQuestion, DNSRecord
66
from .._updates cimport RecordUpdateListener
77
from .._utils.time cimport current_time_millis, millis_to_seconds
8+
from . cimport Signal, SignalRegistrationInterface
89

910

1011
cdef bint TYPE_CHECKING
@@ -23,7 +24,7 @@ cdef class _DNSPointerOutgoingBucket:
2324

2425

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

2829
cdef class QueryScheduler:
2930

src/zeroconf/_services/browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def _enqueue_callback(
388388
state_change is SERVICE_STATE_CHANGE_ADDED
389389
or (
390390
state_change is SERVICE_STATE_CHANGE_REMOVED
391-
and self._pending_handlers.get(key) != SERVICE_STATE_CHANGE_ADDED
391+
and self._pending_handlers.get(key) is not SERVICE_STATE_CHANGE_ADDED
392392
)
393393
or (state_change is SERVICE_STATE_CHANGE_UPDATED and key not in self._pending_handlers)
394394
):

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)