Skip to content

Commit b434b60

Browse files
authored
feat: small cleanups to cache cleanup interval (#1146)
1 parent 524494e commit b434b60

4 files changed

Lines changed: 6 additions & 12 deletions

File tree

src/zeroconf/_core.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ def setup(self, loop: asyncio.AbstractEventLoop, loop_thread_ready: Optional[thr
175175
async def _async_setup(self, loop_thread_ready: Optional[threading.Event]) -> None:
176176
"""Set up the instance."""
177177
assert self.loop is not None
178-
self._cleanup_timer = self.loop.call_later(
179-
millis_to_seconds(_CACHE_CLEANUP_INTERVAL), self._async_cache_cleanup
180-
)
178+
self._cleanup_timer = self.loop.call_later(_CACHE_CLEANUP_INTERVAL, self._async_cache_cleanup)
181179
await self._async_create_endpoints()
182180
assert self.running_event is not None
183181
self.running_event.set()
@@ -213,9 +211,7 @@ def _async_cache_cleanup(self) -> None:
213211
)
214212
self.zc.record_manager.async_updates_complete(False)
215213
assert self.loop is not None
216-
self._cleanup_timer = self.loop.call_later(
217-
millis_to_seconds(_CACHE_CLEANUP_INTERVAL), self._async_cache_cleanup
218-
)
214+
self._cleanup_timer = self.loop.call_later(_CACHE_CLEANUP_INTERVAL, self._async_cache_cleanup)
219215

220216
async def _async_close(self) -> None:
221217
"""Cancel and wait for the cleanup task to finish."""

src/zeroconf/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
_BROWSER_TIME = 1000 # ms
3333
_DUPLICATE_QUESTION_INTERVAL = _BROWSER_TIME - 1 # ms
3434
_BROWSER_BACKOFF_LIMIT = 3600 # s
35-
_CACHE_CLEANUP_INTERVAL = 10000 # ms
35+
_CACHE_CLEANUP_INTERVAL = 10 # s
3636
_LOADED_SYSTEM_TIMEOUT = 10 # s
3737
_STARTUP_TIMEOUT = 9 # s must be lower than _LOADED_SYSTEM_TIMEOUT
3838
_ONE_SECOND = 1000 # ms

tests/services/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def mock_incoming_msg(records: Iterable[r.DNSRecord]) -> r.DNSIncoming:
11201120

11211121

11221122
@patch.object(_handlers, '_DNS_PTR_MIN_TTL', 1)
1123-
@patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 10)
1123+
@patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 0.01)
11241124
def test_service_browser_expire_callbacks():
11251125
"""Test that the ServiceBrowser matching does not match partial names."""
11261126
# instantiate a zeroconf instance

tests/test_core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ async def make_query():
5151
# which is not threadsafe
5252
@pytest.mark.asyncio
5353
async def test_reaper():
54-
with patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 10):
55-
assert _core._CACHE_CLEANUP_INTERVAL == 10
54+
with patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 0.01):
5655
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
5756
zeroconf = aiozc.zeroconf
5857
cache = zeroconf.cache
@@ -88,8 +87,7 @@ async def test_reaper():
8887
@pytest.mark.asyncio
8988
async def test_reaper_aborts_when_done():
9089
"""Ensure cache cleanup stops when zeroconf is done."""
91-
with patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 10):
92-
assert _core._CACHE_CLEANUP_INTERVAL == 10
90+
with patch.object(_core, "_CACHE_CLEANUP_INTERVAL", 0.01):
9391
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
9492
zeroconf = aiozc.zeroconf
9593
record_with_10s_ttl = r.DNSAddress('a', const._TYPE_SOA, const._CLASS_IN, 10, b'a')

0 commit comments

Comments
 (0)