Skip to content

Commit

Permalink
add port occupied test
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <[email protected]>
  • Loading branch information
SajidAlamQB committed Nov 6, 2024
1 parent ce6e6a2 commit e253ada
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion package/tests/test_launchers/test_cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from kedro_viz.autoreload_file_filter import AutoreloadFileFilter
from kedro_viz.launchers.cli import main
from kedro_viz.launchers.cli.run import _VIZ_PROCESSES
from kedro_viz.launchers.utils import _PYPROJECT
from kedro_viz.launchers.utils import _PYPROJECT, _find_available_port
from kedro_viz.server import run_server


Expand Down Expand Up @@ -394,3 +394,17 @@ def test_kedro_viz_command_with_autoreload(
kwargs={**run_process_kwargs},
)
assert run_process_kwargs["kwargs"]["port"] in _VIZ_PROCESSES

# Test case to simulate port occupation and check available port selection
def test_find_available_port_with_occupied_ports(self, mocker):
mock_is_port_in_use = mocker.patch("kedro_viz.launchers.utils._is_port_in_use")

# Mock ports 4141, 4142 being occupied and 4143 is free
mock_is_port_in_use.side_effect = [True, True, False]

available_port = _find_available_port("127.0.0.1", 4141)

# Assert that the function returns the first free port, 4143
assert (
available_port == 4143
), "Expected port 4143 to be returned as the available port"

0 comments on commit e253ada

Please sign in to comment.