test(core): wait for device availability to avoid UI tests flakiness
What changed, and why it matters
This is a test-only change that replaces a fixed 0.1-second sleep with an explicit device-readiness check before starting screen recordings in UI tests. It does not touch firmware, wallet logic, cryptography, or any production code path, so it has no direct security relevance for end users.
No security action required; treat as a normal test-quality patch.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In tests/ui_tests/init.py the screen_recording fixture no longer imports time or ProtocolVersion. The previous workaround—sleep(0.1) to reduce lost DebugLinkRecordScreen packets after a THP event loop restart—is replaced by client.sync_responses(), which actively waits for device availability. This is purely a test-infrastructure robustness improvement.
Changed components
tests/ui_tests/__init__.pyInspect captured patch +3 / −11
diff --git a/tests/ui_tests/__init__.py b/tests/ui_tests/__init__.py
index 483506467..f38acacf6 100644
--- a/tests/ui_tests/__init__.py
+++ b/tests/ui_tests/__init__.py
@@ -2,7 +2,6 @@ from __future__ import annotations
import logging
import shutil
-import time
import typing as t
from contextlib import contextmanager
@@ -10,7 +9,6 @@ import pytest
from _pytest.nodes import Node
from _pytest.outcomes import Failed
-from trezorlib.client import ProtocolVersion
from trezorlib.debuglink import TrezorClientDebugLink as Client
LOG = logging.getLogger(__name__)
@@ -58,15 +56,9 @@ def screen_recording(
shutil.rmtree(testcase.actual_dir, ignore_errors=True)
testcase.actual_dir.mkdir()
- if client.protocol_version is ProtocolVersion.V2:
- # In case of an event loop restart, it's possible that the first
- # packet(s) of `DebugLinkRecordScreen` will be lost, resulting in
- # `TrezorFailure: FirmwareError: Invalid magic` error responses
- # during test setup.
- # This issue will be resolved as part of THP event loop restart refactoring,
- # but till then let's wait a bit here, to reduce the packet loss probability.
- # TODO: remove after THP event loop restart refactoring
- time.sleep(0.1)
+ # Make sure the device is ready - otherwise, the next `DebugLinkRecordScreen` request
+ # may be lost due to an event loop restart.
+ client.sync_responses()
try:
client.debug.start_recording(str(testcase.actual_dir))
yield
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.