Skip to content

Commit ab392f2

Browse files
committed
feat: validate max_join_retries and extract patched_dependencies helper
Raise ValueError if max_join_retries < 0 instead of silently clamping. Extract shared patch context manager to reduce duplication in tests.
1 parent 2a75703 commit ab392f2

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

getstream/video/rtc/connection_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def __init__(
7171
self.session_id: str = str(uuid.uuid4())
7272
self.join_response: Optional[JoinCallResponse] = None
7373
self.local_sfu: bool = False # Local SFU flag for development
74+
if max_join_retries < 0:
75+
raise ValueError("max_join_retries must be >= 0")
7476
self._max_join_retries: int = max_join_retries
7577

7678
# Private attributes

tests/test_connection_manager.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
13
import pytest
24
from unittest.mock import AsyncMock, patch, MagicMock
35

@@ -6,13 +8,9 @@
68
from getstream.video.rtc.pb.stream.video.sfu.models import models_pb2
79

810

9-
@pytest.fixture
10-
def connection_manager(request):
11-
"""Create a ConnectionManager with mocked heavy dependencies.
12-
13-
Accepts max_join_retries via indirect parametrize, defaults to 3.
14-
"""
15-
max_join_retries = getattr(request, "param", 3)
11+
@contextlib.contextmanager
12+
def patched_dependencies():
13+
"""Patch heavy ConnectionManager dependencies for unit testing."""
1614
with (
1715
patch("getstream.video.rtc.connection_manager.PeerConnectionManager"),
1816
patch("getstream.video.rtc.connection_manager.NetworkMonitor"),
@@ -26,6 +24,17 @@ def connection_manager(request):
2624
new_callable=AsyncMock,
2725
),
2826
):
27+
yield
28+
29+
30+
@pytest.fixture
31+
def connection_manager(request):
32+
"""Create a ConnectionManager with mocked heavy dependencies.
33+
34+
Accepts max_join_retries via indirect parametrize, defaults to 3.
35+
"""
36+
max_join_retries = getattr(request, "param", 3)
37+
with patched_dependencies():
2938
mock_call = MagicMock()
3039
mock_call.call_type = "default"
3140
mock_call.id = "test_call"
@@ -153,3 +162,11 @@ async def mock_connect_internal(migrating_from_list=None, **kwargs):
153162
assert call_count == 2
154163
first_ws_client.close.assert_called_once()
155164
assert cm._ws_client is None
165+
166+
def test_rejects_negative_max_join_retries(self):
167+
"""max_join_retries must be >= 0."""
168+
with (
169+
patched_dependencies(),
170+
pytest.raises(ValueError, match="max_join_retries must be >= 0"),
171+
):
172+
ConnectionManager(call=MagicMock(), user_id="user1", max_join_retries=-1)

0 commit comments

Comments
 (0)