1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-21 02:26:10 +00:00

feat(python): ignore unrelated responses

Old responses may be still in the receive queue
(blocking the device from handling new requests).

Let's "flush" them before starting the test.

[no changelog]
This commit is contained in:
Roman Zeyde 2025-03-07 21:25:49 +02:00 committed by Roman Zeyde
parent e1ce484ba7
commit 49c9ad04cd
2 changed files with 10 additions and 2 deletions

View File

@ -21,7 +21,7 @@ import struct
from typing_extensions import Protocol as StructuralType
from . import MessagePayload, Transport
from . import MessagePayload, Timeout, Transport
REPLEN = 64
@ -82,6 +82,14 @@ class Protocol:
def begin_session(self) -> None:
if self.session_counter == 0:
self.handle.open()
try:
# Drop queued responses to old requests
while True:
msg = self.handle.read_chunk(timeout=0.1)
LOG.warning("ignored: %s", msg)
except Timeout:
pass
self.session_counter += 1
def end_session(self) -> None:

View File

@ -28,7 +28,7 @@ from .protocol import ProtocolBasedTransport, ProtocolV1
if TYPE_CHECKING:
from ..models import TrezorModel
SOCKET_TIMEOUT = 10
SOCKET_TIMEOUT = 0.1
LOG = logging.getLogger(__name__)