Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/api_v1/sockets/web_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def websocket_endpoint(websocket: WebSocket) -> None:
# WebSocketDisconnect is not raised unless we poll
# https://github.com/tiangolo/fastapi/issues/3008
try:
message = await asyncio.wait_for(websocket.receive_text(), 0.1)
message = await asyncio.wait_for(websocket.receive_text(), 5.0)
await socket_connection_manager.received_message(
websocket=websocket, message=message
)
Expand Down
4 changes: 2 additions & 2 deletions app/container_manager/container_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ async def __container_ready(self, container: Container) -> None:
raise e

async def __container_started(self, container: Container) -> None:
sleep_interval = 0.2
sleep_interval = 1.0
Comment thread
antonio-amjr marked this conversation as resolved.

while True:
# Check if the container is running, then sleep for 0.1 sec
# Check if the container is running, then sleep
if self.is_running(container):
return

Expand Down
2 changes: 0 additions & 2 deletions app/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def __configure_logging(
logger.add(
sys.stdout,
enqueue=True,
backtrace=True,
level=level.upper(),
format=format,
colorize=colorize,
Expand All @@ -148,7 +147,6 @@ def __configure_logging(
rotation=rotation,
retention=retention,
enqueue=True,
backtrace=True,
level=level.upper(),
format=format,
)
Expand Down
2 changes: 1 addition & 1 deletion app/socket_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def relay_video_frames(self, connection: WebSocketConnection) -> None:
try:
# WebSocketDisconnect is not raised unless we poll
# https://github.com/tiangolo/fastapi/issues/3008
await asyncio.wait_for(websocket.receive_text(), 0.1)
await asyncio.wait_for(websocket.receive_text(), 1.0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In relay_video_frames, when the UDP socket times out (after 1.0 second of no frames), the code polls the websocket with a 1.0-second timeout using asyncio.wait_for(websocket.receive_text(), 1.0). Since this is a receive-only video socket, the client will not send any text, causing this call to block for the full 1.0 second. During this blocking period, any incoming UDP video frames will be buffered or delayed, introducing up to 1.0 second of latency/stuttering when the video stream resumes.

To avoid this latency, consider running the UDP receiver and the websocket disconnect listener concurrently using asyncio.create_task and asyncio.wait(..., return_when=asyncio.FIRST_COMPLETED). This allows immediate detection of websocket disconnection without introducing any blocking delays in the UDP frame relay loop.

except asyncio.TimeoutError:
pass
# Starlette raises websockets.exceptions.ConnectionClosedOK
Expand Down
2 changes: 1 addition & 1 deletion app/test_engine/test_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from app.schemas.test_run_log_entry import TestRunLogEntry
from app.test_engine.models import TestCase, TestRun, TestStep, TestSuite

LOG_PROCESSING_INTERVAL = 0.5
LOG_PROCESSING_INTERVAL = 2.0


class TestLogHandler:
Expand Down
8 changes: 5 additions & 3 deletions app/test_engine/test_ui_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@

class TestUIObserver(Observer):
__test__ = False
__async_updates: list[Task] = []
__last_seen_run_state: Optional[TestStateEnum] = None
__last_seen_run_log_len = 0

def __init__(self) -> None:
self.__async_updates: list[Task] = []

Check failure on line 45 in app/test_engine/test_ui_observer.py

View workflow job for this annotation

GitHub Actions / Flake8

app/test_engine/test_ui_observer.py#L45

Indentation is not a multiple of 4 (E111)
self.__last_seen_run_state: Optional[TestStateEnum] = None

Check failure on line 46 in app/test_engine/test_ui_observer.py

View workflow job for this annotation

GitHub Actions / Flake8

app/test_engine/test_ui_observer.py#L46

Indentation is not a multiple of 4 (E111)
self.__last_seen_run_log_len = 0

Check failure on line 47 in app/test_engine/test_ui_observer.py

View workflow job for this annotation

GitHub Actions / Flake8

app/test_engine/test_ui_observer.py#L47

Indentation is not a multiple of 4 (E111)

def dispatch(
self, observable: Union[TestRun, TestSuite, TestCase, TestStep]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,10 @@ def show_two_way_talk_prompt(self, msg: str) -> None:

def show_push_av_stream_prompt(self, msg: str) -> None:
self.results.put(SDKPythonTestResultShowPushAVStreamPrompt(msg=msg))

def get_update(self) -> tuple[SDKPythonTestResultBase | None, bool]:
"""Returns (update_or_None, is_finished) in a single IPC call."""
try:
return self.results.get(block=False), False
except Empty:
return None, SDKPythonTestRunnerHooks.finished
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,14 @@ async def execute(self) -> None:
logger.error(f"Failed to initialize test output path: {e}")
self.file_output_path = None

while ((update := test_runner_hooks.update_test()) is not None) or (
not test_runner_hooks.is_finished()
):
if not update:
await sleep(0.0001)
continue

await self.__handle_update(update)
while True:
update, finished = test_runner_hooks.get_update()
if update:
await self.__handle_update(update)
elif finished:
break
else:
await sleep(0.2)

# Step: Show test logs
if self.current_test_step_index < len(self.test_steps) - 1:
Expand Down
Loading