tests: don't block forever if a prior unit test raised during setUp
What changed, and why it matters
This is a test-only change that prevents unit tests from hanging forever if an earlier test crashes during setup. It adds a short timeout to a test lock and raises a clear error instead of blocking indefinitely. It does not affect the Electrum wallet software that users run.
No security action needed. This is a benign test infrastructure improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/init.py in Electrum’s test suite. ElectrumTestCase.setUp() previously acquired self._test_lock without a timeout, which could cause tests to block forever if a prior test raised during setUp/asyncSetUp and never released the lock. The patch changes the acquire() call to use a 0.1-second timeout and raises an explicit exception on timeout. This is purely a developer/CI quality-of-life improvement.
Changed components
tests/__init__.pyInspect captured patch +5 / −1
diff --git a/tests/__init__.py b/tests/__init__.py
index 51decf3..492c295 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -55,7 +55,11 @@ class ElectrumTestCase(unittest.IsolatedAsyncioTestCase, Logger):
constants.BitcoinMainnet.set_as_network()
def setUp(self):
- self._test_lock.acquire()
+ have_lock = self._test_lock.acquire(timeout=0.1)
+ if not have_lock:
+ # This can happen when trying to run the tests in parallel,
+ # or if a prior test raised during `setUp` or `asyncSetUp` and never released the lock.
+ raise Exception("timed out waiting for test_lock")
super().setUp()
self.electrum_path = tempfile.mkdtemp(prefix="electrum-unittest-base-")
assert util._asyncio_event_loop is None, "global event loop already set?!"
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.