Files
ServerKit/backend/tests/test_docker_quick_timeouts.py
Juan Denis ec8cd9462e Bound Docker metadata reads with a timeout
ps, inspect, info, version, tag and the network/volume inspects ran
with timeout=None, so a wedged dockerd held every request thread that
asked, forever; the panel runs a single worker process. They now give
up after 30s, and the Containers page reports Docker unreachable.
Pull, build, logs and compose stay unbounded on purpose.
2026-10-10 20:54:12 -04:00

31 lines
980 B
Python

"""Docker metadata reads are bounded.
ps / inspect / info / version ran with timeout=None, so a wedged dockerd
held every request thread that asked forever. Long operations (pull,
build, compose up, logs) stay unbounded on purpose.
"""
from unittest.mock import patch
import pytest
from app.services.docker_service import QUICK_TIMEOUT, DockerService
OK = {'success': True, 'output': '', 'stderr': '', 'error': None, 'returncode': 0}
@pytest.mark.parametrize('call', [
lambda: DockerService.list_containers(),
lambda: DockerService.get_container('abc'),
lambda: DockerService.get_docker_info(),
lambda: DockerService.is_docker_installed(),
lambda: DockerService.tag_image('a:1', 'a:2'),
])
def test_metadata_reads_pass_a_timeout(call):
with patch.object(DockerService, 'run', return_value=OK) as run:
call()
assert run.call_args.kwargs['timeout'] == QUICK_TIMEOUT
def test_quick_timeout_is_bounded():
assert 0 < QUICK_TIMEOUT <= 60