mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-15 19:08:07 +00:00
fix(tests): stop waiting for background task after a timeout
Otherwise a test can hang if the result is not returned. This is not even covered by pytest-timeout because if a test fails, the call to task.kill() happens during teardown, and pytest-timeout doesn't cover that.
This commit is contained in:
parent
f4240d6309
commit
12cf208237
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from typing import TYPE_CHECKING, Any, Callable
|
from typing import TYPE_CHECKING, Any, Callable
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ class BackgroundDeviceHandler:
|
|||||||
while self.client.session_counter > 0:
|
while self.client.session_counter > 0:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
try:
|
try:
|
||||||
self.task.result()
|
self.task.result(timeout=1)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self.task = None
|
self.task = None
|
||||||
@ -80,11 +82,11 @@ class BackgroundDeviceHandler:
|
|||||||
emulator.restart()
|
emulator.restart()
|
||||||
self._configure_client(emulator.client) # type: ignore [client cannot be None]
|
self._configure_client(emulator.client) # type: ignore [client cannot be None]
|
||||||
|
|
||||||
def result(self):
|
def result(self, timeout: float | None = None) -> Any:
|
||||||
if self.task is None:
|
if self.task is None:
|
||||||
raise RuntimeError("No task running")
|
raise RuntimeError("No task running")
|
||||||
try:
|
try:
|
||||||
return self.task.result()
|
return self.task.result(timeout=timeout)
|
||||||
finally:
|
finally:
|
||||||
self.task = None
|
self.task = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user