| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 83fadb1 commit 56f00c5
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -712,43 +712,45 @@ def test_tc_bit_defers_last_response_missing(): | |||
| 712 | 712 | assert len(packets) == 4 | |
| 713 | 713 | expected_deferred = [] | |
| 714 | 714 | ||
| 715 | - # Pin per-packet delay to the minimum so each successive fire_at lands | ||
| 716 | - # before the deadline established by the first packet — keeps the | ||
| 717 | - # timer-replacement assertions deterministic under bounded TC-deferral. | ||
| 718 | - min_delay_ms = _TC_DELAY_RANDOM_INTERVAL[0] | ||
| 719 | - with patch("zeroconf._listener.random.randint", return_value=min_delay_ms): | ||
| 720 | - next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 721 | - expected_deferred.append(next_packet) | ||
| 722 | - threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 723 | - assert protocol._deferred[source_ip] == expected_deferred | ||
| 724 | - timer1 = protocol._timers[source_ip] | ||
| 725 | - | ||
| 726 | - next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 727 | - expected_deferred.append(next_packet) | ||
| 728 | - threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 729 | - assert protocol._deferred[source_ip] == expected_deferred | ||
| 730 | - timer2 = protocol._timers[source_ip] | ||
| 731 | - assert timer1.cancelled() | ||
| 732 | - assert timer2 != timer1 | ||
| 733 | - | ||
| 734 | - # Send the same packet again to similar multi interfaces | ||
| 735 | - threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 736 | - assert protocol._deferred[source_ip] == expected_deferred | ||
| 737 | - assert source_ip in protocol._timers | ||
| 738 | - timer3 = protocol._timers[source_ip] | ||
| 739 | - assert not timer3.cancelled() | ||
| 740 | - assert timer3 == timer2 | ||
| 741 | - | ||
| 742 | - next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 743 | - expected_deferred.append(next_packet) | ||
| 744 | - threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 745 | - assert protocol._deferred[source_ip] == expected_deferred | ||
| 746 | - assert source_ip in protocol._timers | ||
| 747 | - timer4 = protocol._timers[source_ip] | ||
| 748 | - assert timer3.cancelled() | ||
| 749 | - assert timer4 != timer3 | ||
| 750 | - | ||
| 751 | - for _ in range(8): | ||
| 715 | + # Widen the per-packet delay so Windows scheduling jitter between | ||
| 716 | + # assertions cannot fire the timer mid-test, while leaving plenty of | ||
| 717 | + # headroom under the first-arrival deadline for timer-replacement to | ||
| 718 | + # remain deterministic. | ||
| 719 | + with patch.object(_listener, "_TC_DELAY_RANDOM_INTERVAL", (1500, 60_000)): | ||
| 720 | + min_delay_ms = _listener._TC_DELAY_RANDOM_INTERVAL[0] | ||
| 721 | + with patch("zeroconf._listener.random.randint", return_value=min_delay_ms): | ||
| 722 | + next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 723 | + expected_deferred.append(next_packet) | ||
| 724 | + threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 725 | + assert protocol._deferred[source_ip] == expected_deferred | ||
| 726 | + timer1 = protocol._timers[source_ip] | ||
| 727 | + | ||
| 728 | + next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 729 | + expected_deferred.append(next_packet) | ||
| 730 | + threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 731 | + assert protocol._deferred[source_ip] == expected_deferred | ||
| 732 | + timer2 = protocol._timers[source_ip] | ||
| 733 | + assert timer1.cancelled() | ||
| 734 | + assert timer2 != timer1 | ||
| 735 | + | ||
| 736 | + # Send the same packet again to similar multi interfaces | ||
| 737 | + threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 738 | + assert protocol._deferred[source_ip] == expected_deferred | ||
| 739 | + assert source_ip in protocol._timers | ||
| 740 | + timer3 = protocol._timers[source_ip] | ||
| 741 | + assert not timer3.cancelled() | ||
| 742 | + assert timer3 == timer2 | ||
| 743 | + | ||
| 744 | + next_packet = r.DNSIncoming(packets.pop(0)) | ||
| 745 | + expected_deferred.append(next_packet) | ||
| 746 | + threadsafe_query(zc, protocol, next_packet, source_ip, const._MDNS_PORT, Mock(), ()) | ||
| 747 | + assert protocol._deferred[source_ip] == expected_deferred | ||
| 748 | + assert source_ip in protocol._timers | ||
| 749 | + timer4 = protocol._timers[source_ip] | ||
| 750 | + assert timer3.cancelled() | ||
| 751 | + assert timer4 != timer3 | ||
| 752 | + | ||
| 753 | + for _ in range(30): | ||
| 752 | 754 | time.sleep(0.1) | |
| 753 | 755 | if source_ip not in protocol._timers and source_ip not in protocol._deferred: | |
| 754 | 756 | break | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -590,6 +590,12 @@ def test_autodetect_ip_version_non_list_interfaces_with_multicast_addresses() -> | |||
| 590 | 590 | ) | |
| 591 | 591 | ||
| 592 | 592 | ||
| 593 | + def test_autodetect_ip_version_interface_index_treated_as_v6() -> None: | ||
| 594 | + """Interface-index (int) entries are treated as IPv6 by autodetection.""" | ||
| 595 | + assert netutils.autodetect_ip_version([1]) is r.IPVersion.V6Only | ||
| 596 | + assert netutils.autodetect_ip_version(["1.2.3.4", 1]) is r.IPVersion.All | ||
| 597 | + | ||
| 598 | + | ||
| 593 | 599 | def test_create_sockets_multicast_addresses_ip_version_all() -> None: | |
| 594 | 600 | """multicast_addresses works with ip_version=All (no V4Only/V6Only validation triggered).""" | |
| 595 | 601 | listen_mock = Mock(spec=socket.socket) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments