Skip to content

Commit 9a3bf0a

Browse files
committed
test, bitbox02: add 5 minute startup timeout
Wrap the Bitbox02Client initialization and restore_device() call in a thread with a 5 minute timeout. This prevents CI from hanging for 45 minutes when the simulator startup blocks indefinitely.
1 parent 0eed6b3 commit 9a3bf0a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

test/test_bitbox02.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import subprocess
66
import time
7+
import threading
78
import unittest
89
import sys
910
import argparse
@@ -22,6 +23,9 @@
2223

2324
# Class for emulator control
2425
class BitBox02Emulator(DeviceEmulator):
26+
# Maximum time to wait for simulator startup (5 minutes)
27+
MAX_STARTUP_TIME = 300
28+
2529
def __init__(self, simulator):
2630
self.simulator = simulator
2731
self.path = "127.0.0.1:15423"
@@ -55,9 +59,26 @@ def start(self):
5559
if self.simulator_proc.poll() is not None:
5660
raise RuntimeError(f"BitBox02 simulator failed with exit code {self.simulator_proc.poll()}")
5761

58-
self.setup_client = Bitbox02Client(self.path)
59-
self.setup_bb02 = self.setup_client.restore_device()
60-
self.setup_client.close()
62+
# Run restore_device in a thread with timeout to prevent CI from hanging
63+
setup_error = None
64+
def do_restore():
65+
nonlocal setup_error
66+
try:
67+
self.setup_client = Bitbox02Client(self.path)
68+
self.setup_bb02 = self.setup_client.restore_device()
69+
self.setup_client.close()
70+
except Exception as e:
71+
setup_error = e
72+
73+
restore_thread = threading.Thread(target=do_restore)
74+
restore_thread.start()
75+
restore_thread.join(timeout=self.MAX_STARTUP_TIME)
76+
77+
if restore_thread.is_alive():
78+
self.simulator_proc.terminate()
79+
raise RuntimeError("BitBox02 simulator startup timed out after 5 minutes")
80+
if setup_error:
81+
raise setup_error
6182

6283
atexit.register(self.stop)
6384

0 commit comments

Comments
 (0)