Skip to content

Commit 3b482e2

Browse files
authored
Fix flakey test: test_future_answers_are_removed_on_send (#962)
1 parent 2d1b832 commit 3b482e2

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

tests/test_handlers.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,29 +1466,34 @@ async def test_response_aggregation_random_delay():
14661466
async def test_future_answers_are_removed_on_send():
14671467
"""Verify any future answers scheduled to be sent are removed when we send."""
14681468
type_ = "_mservice._tcp.local."
1469+
type_2 = "_mservice2._tcp.local."
14691470
name = "xxxyyy"
14701471
registration_name = f"{name}.{type_}"
1472+
registration_name2 = f"{name}.{type_2}"
14711473

14721474
desc = {'path': '/~paulsm/'}
14731475
info = ServiceInfo(
14741476
type_, registration_name, 80, 0, 0, desc, "ash-1.local.", addresses=[socket.inet_aton("10.0.1.2")]
14751477
)
1478+
info2 = ServiceInfo(
1479+
type_2, registration_name2, 80, 0, 0, desc, "ash-2.local.", addresses=[socket.inet_aton("10.0.1.3")]
1480+
)
14761481
mocked_zc = unittest.mock.MagicMock()
14771482
outgoing_queue = MulticastOutgoingQueue(mocked_zc, 0, 0)
14781483

14791484
now = current_time_millis()
1480-
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (10, 10)):
1485+
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (1, 1)):
14811486
outgoing_queue.async_add(now, {info.dns_pointer(): set()})
14821487

14831488
assert len(outgoing_queue.queue) == 1
14841489

1485-
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (20, 20)):
1490+
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (2, 2)):
14861491
outgoing_queue.async_add(now, {info.dns_pointer(): set()})
14871492

14881493
assert len(outgoing_queue.queue) == 2
14891494

1490-
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (200, 200)):
1491-
outgoing_queue.async_add(now, {info.dns_pointer(): set()})
1495+
with unittest.mock.patch.object(_handlers, "_MULTICAST_DELAY_RANDOM_INTERVAL", (1000, 1000)):
1496+
outgoing_queue.async_add(now, {info2.dns_pointer(): set()})
14921497
outgoing_queue.async_add(now, {info.dns_pointer(): set()})
14931498

14941499
assert len(outgoing_queue.queue) == 3
@@ -1497,5 +1502,8 @@ async def test_future_answers_are_removed_on_send():
14971502
outgoing_queue.async_ready()
14981503

14991504
assert len(outgoing_queue.queue) == 1
1500-
# The answers should all get removed because we just sent them
1501-
assert len(outgoing_queue.queue[0].answers) == 0
1505+
# The answer should get removed because we just sent it
1506+
assert info.dns_pointer() not in outgoing_queue.queue[0].answers
1507+
1508+
# But the one we have not sent yet shoudl still go out later
1509+
assert info2.dns_pointer() in outgoing_queue.queue[0].answers

0 commit comments

Comments
 (0)