Skip to content

Commit fc0e599

Browse files
authored
Fix race condition in ServiceBrowser test_integration (#762)
- The event was being cleared in the wrong thread which meant if the test was fast enough it would not be seen the second time and give a spurious failure
1 parent 936500a commit fc0e599

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

tests/services/test_browser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ def current_time_millis():
441441
return time.time() * 1000 + time_offset * 1000
442442

443443
expected_ttl = const._DNS_HOST_TTL
444-
445444
nbr_answers = 0
446445

447446
def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
@@ -454,6 +453,8 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
454453
unexpected_ttl.set()
455454

456455
got_query.set()
456+
got_query.clear()
457+
457458
old_send(out, addr=addr, port=port)
458459

459460
# patch the zeroconf send
@@ -482,13 +483,13 @@ def send(out, addr=const._MDNS_ADDR, port=const._MDNS_PORT):
482483
# is greater than half the original TTL
483484
sleep_count = 0
484485
test_iterations = 50
486+
485487
while nbr_answers < test_iterations:
486488
# Increase simulated time shift by 1/4 of the TTL in seconds
487489
time_offset += expected_ttl / 4
488490
zeroconf_browser.notify_all()
489491
sleep_count += 1
490492
got_query.wait(0.1)
491-
got_query.clear()
492493
# Prevent the test running indefinitely in an error condition
493494
assert sleep_count < test_iterations * 4
494495
assert not unexpected_ttl.is_set()

0 commit comments

Comments
 (0)