Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions tests/services/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_only_register_once(self):
)

registry = r.ServiceRegistry()
registry.add(info)
self.assertRaises(r.ServiceNameAlreadyRegistered, registry.add, info)
registry.remove(info)
registry.add(info)
registry.async_add(info)
self.assertRaises(r.ServiceNameAlreadyRegistered, registry.async_add, info)
registry.async_remove(info)
registry.async_add(info)

def test_unregister_multiple_times(self):
"""Verify we can unregister a service multiple times.
Expand All @@ -46,10 +46,10 @@ def test_unregister_multiple_times(self):
)

registry = r.ServiceRegistry()
registry.add(info)
self.assertRaises(r.ServiceNameAlreadyRegistered, registry.add, info)
registry.remove(info)
registry.remove(info)
registry.async_add(info)
self.assertRaises(r.ServiceNameAlreadyRegistered, registry.async_add, info)
registry.async_remove(info)
registry.async_remove(info)

def test_lookups(self):
type_ = "_test-srvc-type._tcp.local."
Expand All @@ -62,13 +62,13 @@ def test_lookups(self):
)

registry = r.ServiceRegistry()
registry.add(info)
registry.async_add(info)

assert registry.get_service_infos() == [info]
assert registry.get_info_name(registration_name) == info
assert registry.get_infos_type(type_) == [info]
assert registry.get_infos_server("ash-2.local.") == [info]
assert registry.get_types() == [type_]
assert registry.async_get_service_infos() == [info]
assert registry.async_get_info_name(registration_name) == info
assert registry.async_get_infos_type(type_) == [info]
assert registry.async_get_infos_server("ash-2.local.") == [info]
assert registry.async_get_types() == [type_]

def test_lookups_upper_case_by_lower_case(self):
type_ = "_test-SRVC-type._tcp.local."
Expand All @@ -81,13 +81,13 @@ def test_lookups_upper_case_by_lower_case(self):
)

registry = r.ServiceRegistry()
registry.add(info)
registry.async_add(info)

assert registry.get_service_infos() == [info]
assert registry.get_info_name(registration_name.lower()) == info
assert registry.get_infos_type(type_.lower()) == [info]
assert registry.get_infos_server("ash-2.local.") == [info]
assert registry.get_types() == [type_.lower()]
assert registry.async_get_service_infos() == [info]
assert registry.async_get_info_name(registration_name.lower()) == info
assert registry.async_get_infos_type(type_.lower()) == [info]
assert registry.async_get_infos_server("ash-2.local.") == [info]
assert registry.async_get_types() == [type_.lower()]

def test_lookups_lower_case_by_upper_case(self):
type_ = "_test-srvc-type._tcp.local."
Expand All @@ -100,10 +100,10 @@ def test_lookups_lower_case_by_upper_case(self):
)

registry = r.ServiceRegistry()
registry.add(info)
registry.async_add(info)

assert registry.get_service_infos() == [info]
assert registry.get_info_name(registration_name.upper()) == info
assert registry.get_infos_type(type_.upper()) == [info]
assert registry.get_infos_server("ASH-2.local.") == [info]
assert registry.get_types() == [type_]
assert registry.async_get_service_infos() == [info]
assert registry.async_get_info_name(registration_name.upper()) == info
assert registry.async_get_infos_type(type_.upper()) == [info]
assert registry.async_get_infos_server("ASH-2.local.") == [info]
assert registry.async_get_types() == [type_]
8 changes: 4 additions & 4 deletions tests/services/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_integration_with_listener(self):
"ash-2.local.",
addresses=[socket.inet_aton("10.0.1.2")],
)
zeroconf_registrar.registry.add(info)
zeroconf_registrar.registry.async_add(info)
try:
with patch.object(
zeroconf_registrar.engine.protocols[0], "suppress_duplicate_packet", return_value=False
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_integration_with_listener_v6_records(self):
"ash-2.local.",
addresses=[socket.inet_pton(socket.AF_INET6, addr)],
)
zeroconf_registrar.registry.add(info)
zeroconf_registrar.registry.async_add(info)
try:
with patch.object(
zeroconf_registrar.engine.protocols[0], "suppress_duplicate_packet", return_value=False
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_integration_with_listener_ipv6(self):
"ash-2.local.",
addresses=[socket.inet_pton(socket.AF_INET6, addr)],
)
zeroconf_registrar.registry.add(info)
zeroconf_registrar.registry.async_add(info)
try:
with patch.object(
zeroconf_registrar.engine.protocols[0], "suppress_duplicate_packet", return_value=False
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_integration_with_subtype_and_listener(self):
"ash-2.local.",
addresses=[socket.inet_aton("10.0.1.2")],
)
zeroconf_registrar.registry.add(info)
zeroconf_registrar.registry.async_add(info)
try:
with patch.object(
zeroconf_registrar.engine.protocols[0], "suppress_duplicate_packet", return_value=False
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ async def test_info_asking_default_is_asking_qm_questions_after_the_first_qu():
type_, registration_name, 80, 0, 0, desc, "ash-2.local.", addresses=[socket.inet_aton("10.0.1.2")]
)

zeroconf_info.registry.add(info)
zeroconf_info.registry.async_add(info)

# we are going to patch the zeroconf send to check query transmission
old_send = zeroconf_info.async_send
Expand Down
20 changes: 10 additions & 10 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ def test_goodbye_all_services():
info = r.ServiceInfo(
type_, registration_name, 80, 0, 0, desc, "ash-2.local.", addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.async_add(info)
out = zc.generate_unregister_all_services()
assert out is not None
first_packet = out.packets()
zc.registry.add(info)
zc.registry.async_add(info)
out2 = zc.generate_unregister_all_services()
assert out2 is not None
second_packet = out.packets()
Expand All @@ -348,7 +348,7 @@ def test_goodbye_all_services():
# Verify the registery is empty
out3 = zc.generate_unregister_all_services()
assert out3 is None
assert zc.registry.get_service_infos() == []
assert zc.registry.async_get_service_infos() == []

zc.close()

Expand Down Expand Up @@ -438,9 +438,9 @@ def test_tc_bit_defers():
info3 = r.ServiceInfo(
type_, registration3_name, 80, 0, 0, desc, server_name3, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.add(info2)
zc.registry.add(info3)
zc.registry.async_add(info)
zc.registry.async_add(info2)
zc.registry.async_add(info3)

protocol = zc.engine.protocols[0]
now = r.current_time_millis()
Expand Down Expand Up @@ -517,9 +517,9 @@ def test_tc_bit_defers_last_response_missing():
info3 = r.ServiceInfo(
type_, registration3_name, 80, 0, 0, desc, server_name3, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.add(info2)
zc.registry.add(info3)
zc.registry.async_add(info)
zc.registry.async_add(info2)
zc.registry.async_add(info3)

protocol = zc.engine.protocols[0]
now = r.current_time_millis()
Expand Down Expand Up @@ -581,7 +581,7 @@ def test_tc_bit_defers_last_response_missing():
assert source_ip not in protocol._timers

# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand Down
54 changes: 27 additions & 27 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _process_outgoing_packet(out):
expected_ttl = None
for _ in range(3):
_process_outgoing_packet(zc.generate_service_query(info))
zc.registry.add(info)
zc.registry.async_add(info)
for _ in range(3):
_process_outgoing_packet(zc.generate_service_broadcast(info, None))
assert nbr_answers == 12 and nbr_additionals == 0 and nbr_authorities == 3
Expand All @@ -112,7 +112,7 @@ def _process_outgoing_packet(out):

# unregister
expected_ttl = 0
zc.registry.remove(info)
zc.registry.async_remove(info)
for _ in range(3):
_process_outgoing_packet(zc.generate_service_broadcast(info, 0))
assert nbr_answers == 12 and nbr_additionals == 0 and nbr_authorities == 0
Expand All @@ -121,7 +121,7 @@ def _process_outgoing_packet(out):
expected_ttl = None
for _ in range(3):
_process_outgoing_packet(zc.generate_service_query(info))
zc.registry.add(info)
zc.registry.async_add(info)
# register service with custom TTL
expected_ttl = const._DNS_HOST_TTL * 2
assert expected_ttl != const._DNS_HOST_TTL
Expand All @@ -147,7 +147,7 @@ def _process_outgoing_packet(out):

# unregister
expected_ttl = 0
zc.registry.remove(info)
zc.registry.async_remove(info)
for _ in range(3):
_process_outgoing_packet(zc.generate_service_broadcast(info, 0))
assert nbr_answers == 12 and nbr_additionals == 0 and nbr_authorities == 0
Expand Down Expand Up @@ -284,7 +284,7 @@ def test_any_query_for_ptr():
server_name = "ash-2.local."
ipv6_address = socket.inet_pton(socket.AF_INET6, "2001:db8::1")
info = ServiceInfo(type_, registration_name, 80, 0, 0, desc, server_name, addresses=[ipv6_address])
zc.registry.add(info)
zc.registry.async_add(info)

_clear_cache(zc)
generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
Expand All @@ -297,7 +297,7 @@ def test_any_query_for_ptr():
assert multicast_out.answers[0][0].name == type_
assert multicast_out.answers[0][0].alias == registration_name
# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand All @@ -311,7 +311,7 @@ def test_aaaa_query():
server_name = "ash-2.local."
ipv6_address = socket.inet_pton(socket.AF_INET6, "2001:db8::1")
info = ServiceInfo(type_, registration_name, 80, 0, 0, desc, server_name, addresses=[ipv6_address])
zc.registry.add(info)
zc.registry.async_add(info)

generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
question = r.DNSQuestion(server_name, const._TYPE_AAAA, const._CLASS_IN)
Expand All @@ -322,7 +322,7 @@ def test_aaaa_query():
)
assert multicast_out.answers[0][0].address == ipv6_address
# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand All @@ -342,7 +342,7 @@ def test_a_and_aaaa_record_fate_sharing():
aaaa_record = info.dns_addresses(version=r.IPVersion.V6Only)[0]
a_record = info.dns_addresses(version=r.IPVersion.V4Only)[0]

zc.registry.add(info)
zc.registry.async_add(info)

# Test AAAA query
generated = r.DNSOutgoing(const._FLAGS_QR_QUERY)
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_a_and_aaaa_record_fate_sharing():
assert len(multicast_out.answers) == 1
assert len(multicast_out.additionals) == 1
# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand All @@ -393,7 +393,7 @@ def test_unicast_response():
type_, registration_name, 80, 0, 0, desc, "ash-2.local.", addresses=[socket.inet_aton("10.0.1.2")]
)
# register
zc.registry.add(info)
zc.registry.async_add(info)
_clear_cache(zc)

# query
Expand All @@ -420,7 +420,7 @@ def test_unicast_response():
assert has_srv and has_txt and has_a

# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand Down Expand Up @@ -535,7 +535,7 @@ def test_known_answer_supression():
info = ServiceInfo(
type_, registration_name, 80, 0, 0, desc, server_name, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.async_add(info)

now = current_time_millis()
_clear_cache(zc)
Expand Down Expand Up @@ -631,7 +631,7 @@ def test_known_answer_supression():
assert not multicast_out or not multicast_out.answers

# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
zc.close()


Expand Down Expand Up @@ -660,9 +660,9 @@ def test_multi_packet_known_answer_supression():
info3 = ServiceInfo(
type_, registration3_name, 80, 0, 0, desc, server_name3, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.add(info2)
zc.registry.add(info3)
zc.registry.async_add(info)
zc.registry.async_add(info2)
zc.registry.async_add(info3)

now = current_time_millis()
_clear_cache(zc)
Expand All @@ -683,9 +683,9 @@ def test_multi_packet_known_answer_supression():
assert unicast_out is None
assert multicast_out is None
# unregister
zc.registry.remove(info)
zc.registry.remove(info2)
zc.registry.remove(info3)
zc.registry.async_remove(info)
zc.registry.async_remove(info2)
zc.registry.async_remove(info3)
zc.close()


Expand All @@ -699,7 +699,7 @@ def test_known_answer_supression_service_type_enumeration_query():
info = ServiceInfo(
type_, registration_name, 80, 0, 0, desc, server_name, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.async_add(info)

type_2 = "_otherknown2._tcp.local."
name = "knownname"
Expand All @@ -709,7 +709,7 @@ def test_known_answer_supression_service_type_enumeration_query():
info2 = ServiceInfo(
type_2, registration_name2, 80, 0, 0, desc, server_name2, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info2)
zc.registry.async_add(info2)
now = current_time_millis()
_clear_cache(zc)

Expand Down Expand Up @@ -755,8 +755,8 @@ def test_known_answer_supression_service_type_enumeration_query():
assert not multicast_out or not multicast_out.answers

# unregister
zc.registry.remove(info)
zc.registry.remove(info2)
zc.registry.async_remove(info)
zc.registry.async_remove(info2)
zc.close()


Expand All @@ -777,7 +777,7 @@ async def test_qu_response_only_sends_additionals_if_sends_answer():
info = ServiceInfo(
type_, registration_name, 80, 0, 0, desc, server_name, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info)
zc.registry.async_add(info)

type_2 = "_addtest2._tcp.local."
name = "knownname"
Expand All @@ -787,7 +787,7 @@ async def test_qu_response_only_sends_additionals_if_sends_answer():
info2 = ServiceInfo(
type_2, registration_name2, 80, 0, 0, desc, server_name2, addresses=[socket.inet_aton("10.0.1.2")]
)
zc.registry.add(info2)
zc.registry.async_add(info2)

ptr_record = info.dns_pointer()

Expand Down Expand Up @@ -888,7 +888,7 @@ async def test_qu_response_only_sends_additionals_if_sends_answer():
assert info2.dns_service() in unicast_out.additionals

# unregister
zc.registry.remove(info)
zc.registry.async_remove(info)
await aiozc.async_close()


Expand Down
Loading