|
18 | 18 | from zeroconf._services import ServiceInfo, ServiceListener |
19 | 19 | from zeroconf._utils.time import current_time_millis |
20 | 20 |
|
| 21 | +from . import _clear_cache |
| 22 | + |
21 | 23 |
|
22 | 24 | from . import _clear_cache |
23 | 25 |
|
@@ -498,3 +500,61 @@ async def test_async_context_manager() -> None: |
498 | 500 | await task |
499 | 501 | aiosinfo = await aiozc.async_get_service_info(type_, registration_name) |
500 | 502 | assert aiosinfo is not None |
| 503 | + |
| 504 | + |
| 505 | +@pytest.mark.asyncio |
| 506 | +async def test_async_unregister_all_services() -> None: |
| 507 | + """Test unregistering all services.""" |
| 508 | + aiozc = AsyncZeroconf(interfaces=['127.0.0.1']) |
| 509 | + type_ = "_test1-srvc-type._tcp.local." |
| 510 | + name = "xxxyyy" |
| 511 | + name2 = "abc" |
| 512 | + registration_name = "%s.%s" % (name, type_) |
| 513 | + registration_name2 = "%s.%s" % (name2, type_) |
| 514 | + |
| 515 | + desc = {'path': '/~paulsm/'} |
| 516 | + info = ServiceInfo( |
| 517 | + type_, |
| 518 | + registration_name, |
| 519 | + 80, |
| 520 | + 0, |
| 521 | + 0, |
| 522 | + desc, |
| 523 | + "ash-1.local.", |
| 524 | + addresses=[socket.inet_aton("10.0.1.2")], |
| 525 | + ) |
| 526 | + info2 = ServiceInfo( |
| 527 | + type_, |
| 528 | + registration_name2, |
| 529 | + 80, |
| 530 | + 0, |
| 531 | + 0, |
| 532 | + desc, |
| 533 | + "ash-5.local.", |
| 534 | + addresses=[socket.inet_aton("10.0.1.5")], |
| 535 | + ) |
| 536 | + tasks = [] |
| 537 | + tasks.append(await aiozc.async_register_service(info)) |
| 538 | + tasks.append(await aiozc.async_register_service(info2)) |
| 539 | + await asyncio.gather(*tasks) |
| 540 | + |
| 541 | + tasks = [] |
| 542 | + tasks.append(aiozc.async_get_service_info(type_, registration_name)) |
| 543 | + tasks.append(aiozc.async_get_service_info(type_, registration_name2)) |
| 544 | + results = await asyncio.gather(*tasks) |
| 545 | + assert results[0] is not None |
| 546 | + assert results[1] is not None |
| 547 | + |
| 548 | + await aiozc.async_unregister_all_services() |
| 549 | + |
| 550 | + tasks = [] |
| 551 | + tasks.append(aiozc.async_get_service_info(type_, registration_name)) |
| 552 | + tasks.append(aiozc.async_get_service_info(type_, registration_name2)) |
| 553 | + results = await asyncio.gather(*tasks) |
| 554 | + assert results[0] is None |
| 555 | + assert results[1] is None |
| 556 | + |
| 557 | + # Verify we can call again |
| 558 | + await aiozc.async_unregister_all_services() |
| 559 | + |
| 560 | + await aiozc.async_close() |
0 commit comments