Skip to content

Commit 52c304e

Browse files
committed
Fix thread safety in handlers test
1 parent 72502c3 commit 52c304e

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

tests/test_handlers.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,10 @@ def async_update_records(self, zc: 'Zeroconf', now: float, records: List[r.Recor
10221022
await aiozc.async_close()
10231023

10241024

1025-
def test_questions_query_handler_populates_the_question_history_from_qm_questions():
1026-
zc = Zeroconf(interfaces=['127.0.0.1'])
1025+
@pytest.mark.asyncio
1026+
async def test_questions_query_handler_populates_the_question_history_from_qm_questions():
1027+
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
1028+
zc = aiozc.zeroconf
10271029
now = current_time_millis()
10281030
_clear_cache(zc)
10291031

@@ -1044,11 +1046,13 @@ def test_questions_query_handler_populates_the_question_history_from_qm_question
10441046
assert multicast_out is None
10451047
assert zc.question_history.suppresses(question, now, set([known_answer]))
10461048

1047-
zc.close()
1049+
await aiozc.async_close()
10481050

10491051

1050-
def test_questions_query_handler_does_not_put_qu_questions_in_history():
1051-
zc = Zeroconf(interfaces=['127.0.0.1'])
1052+
@pytest.mark.asyncio
1053+
async def test_questions_query_handler_does_not_put_qu_questions_in_history():
1054+
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
1055+
zc = aiozc.zeroconf
10521056
now = current_time_millis()
10531057
_clear_cache(zc)
10541058

@@ -1069,17 +1073,19 @@ def test_questions_query_handler_does_not_put_qu_questions_in_history():
10691073
assert multicast_out is None
10701074
assert not zc.question_history.suppresses(question, now, set([known_answer]))
10711075

1072-
zc.close()
1076+
await aiozc.async_close()
10731077

10741078

1075-
def test_guard_against_low_ptr_ttl():
1079+
@pytest.mark.asyncio
1080+
async def test_guard_against_low_ptr_ttl():
10761081
"""Ensure we enforce a minimum for PTR record ttls to avoid excessive refresh queries from ServiceBrowsers.
10771082
10781083
Some poorly designed IoT devices can set excessively low PTR
10791084
TTLs would will cause ServiceBrowsers to flood the network
10801085
with excessive refresh queries.
10811086
"""
1082-
zc = Zeroconf(interfaces=['127.0.0.1'])
1087+
aiozc = AsyncZeroconf(interfaces=['127.0.0.1'])
1088+
zc = aiozc.zeroconf
10831089
# Apple uses a 15s minimum TTL, however we do not have the same
10841090
# level of rate limit and safe guards so we use 1/4 of the recommended value
10851091
answer_with_low_ttl = r.DNSPointer(
@@ -1116,4 +1122,4 @@ def test_guard_against_low_ptr_ttl():
11161122
incoming_answer_normal = zc.cache.async_get_unique(answer_with_normal_ttl)
11171123
assert incoming_answer_normal.ttl == const._DNS_OTHER_TTL
11181124
assert zc.cache.async_get_unique(good_bye_answer) is None
1119-
zc.close()
1125+
await aiozc.async_close()

0 commit comments

Comments
 (0)