Skip to content

Commit 639792c

Browse files
committed
Fix CI test failure in test_port_manager_high_queue_utilization_warning
1 parent 252396e commit 639792c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/lightning/fabric/utilities/port_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ def allocate_port(self, preferred_port: Optional[int] = None, max_attempts: int
231231

232232
self._allocated_ports.add(port)
233233

234+
# Log diagnostics if queue utilization is high (>78%)
234235
queue_count = len(state.recently_released)
235-
if queue_count > 800: # >78% of typical 1024 capacity
236+
threshold = int(_RECENTLY_RELEASED_PORTS_MAXLEN * 0.78)
237+
if queue_count > threshold:
236238
utilization_pct = (queue_count / _RECENTLY_RELEASED_PORTS_MAXLEN) * 100
237239
log.warning(
238240
f"Port queue utilization high: {queue_count} entries ({utilization_pct:.1f}% of capacity). "

tests/tests_fabric/utilities/test_port_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,17 +784,21 @@ def test_port_manager_reserve_clears_recently_released():
784784
manager.release_port(port)
785785

786786

787-
def test_port_manager_high_queue_utilization_warning(monkeypatch, caplog):
787+
def test_port_manager_high_queue_utilization_warning(monkeypatch, caplog, tmpdir):
788788
"""Test that warning is logged when queue utilization exceeds 80%."""
789789
import logging
790+
from pathlib import Path
790791

791792
_set_recently_released_limit(monkeypatch, 64)
792793

793794
queue_limit = port_manager_module._RECENTLY_RELEASED_PORTS_MAXLEN
794795
trigger_count = int(queue_limit * 0.8) + 1 # Just over 80%
795796
expected_pct = (trigger_count / queue_limit) * 100
796797

797-
manager = PortManager()
798+
# Use isolated state to avoid contamination from other tests
799+
lock_file = Path(tmpdir) / "test.lock"
800+
state_file = Path(tmpdir) / "test_state.json"
801+
manager = PortManager(lock_file=lock_file, state_file=state_file)
798802

799803
# Fill queue to just over 80%
800804
for _ in range(trigger_count):

0 commit comments

Comments
 (0)