Skip to content

Commit 765ab8d

Browse files
Fix fragile tests (#325)
The previous push to `master` failed to deploy because of a flaky Windows test.
1 parent 5966ff7 commit 765ab8d

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

pycyphal/transport/can/media/candump/_candump.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ def close(self) -> None:
146146
self._f.close()
147147
self._thread, thd = None, self._thread
148148
assert thd is not None
149-
thd.join(timeout=1)
149+
try:
150+
thd.join(timeout=1)
151+
except RuntimeError:
152+
pass
150153

151154
@property
152155
def _is_closed(self) -> bool:

pycyphal/transport/can/media/pythoncan/_pythoncan.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,15 @@ def close(self) -> None:
323323
self._closed = True
324324
try:
325325
self._tx_queue.put(None)
326-
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
326+
try:
327+
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
328+
except RuntimeError:
329+
pass
327330
if self._maybe_thread is not None:
328-
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
331+
try:
332+
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
333+
except RuntimeError:
334+
pass
329335
self._maybe_thread = None
330336
finally:
331337
try:

pycyphal/transport/can/media/socketcan/_socketcan.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ def close(self) -> None:
165165
if self._ctl_main.fileno() >= 0: # Ignore if already closed.
166166
self._ctl_main.send(b"stop") # The actual data is irrelevant, we just need it to unblock the select().
167167
if self._maybe_thread:
168-
self._maybe_thread.join(timeout=_SELECT_TIMEOUT)
168+
try:
169+
self._maybe_thread.join(timeout=_SELECT_TIMEOUT)
170+
except RuntimeError:
171+
pass
169172
self._maybe_thread = None
170173
finally:
171174
self._sock.close() # These are expected to be idempotent.

pycyphal/transport/can/media/socketcand/_socketcand.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,15 @@ def close(self) -> None:
203203
self._closed = True
204204
try:
205205
self._tx_queue.put(None)
206-
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
206+
try:
207+
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
208+
except RuntimeError:
209+
pass
207210
if self._maybe_thread is not None:
208-
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
211+
try:
212+
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
213+
except RuntimeError:
214+
pass
209215
self._maybe_thread = None
210216
finally:
211217
try:

tests/demo/_demo_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ async def _unittest_slow_demo_app(
310310
assert hb.health.value == hb.health.NOMINAL
311311
assert hb.mode.value == hb.mode.OPERATIONAL
312312
assert num_heartbeats <= hb.uptime <= 300
313-
assert prev_hb_transfer[0].uptime <= hb.uptime <= prev_hb_transfer[0].uptime + 1
313+
assert prev_hb_transfer[0].uptime <= hb.uptime <= prev_hb_transfer[0].uptime + 2 # +2 due to aliasing
314314
assert transfer.transfer_id == prev_hb_transfer[1].transfer_id + 1
315315
prev_hb_transfer = hb_transfer
316316
num_heartbeats += 1

tests/transport/can/media/_pythoncan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def _unittest_can_pythoncan_iface_name() -> None:
164164
# multiple colons are allowed in interface names, only the first one is split
165165
media = PythonCANMedia("virtual:0:0", 1_000_000)
166166
assert media.interface_name == "virtual:0:0"
167+
media.close()
167168

168169

169170
def _unittest_can_pythoncan_errors() -> None:

0 commit comments

Comments
 (0)