Skip to content

Commit

Permalink
Fix fragile tests (#325)
Browse files Browse the repository at this point in the history
The previous push to `master` failed to deploy because of a flaky
Windows test.
  • Loading branch information
pavel-kirienko authored Jan 18, 2024
1 parent 5966ff7 commit 765ab8d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
5 changes: 4 additions & 1 deletion pycyphal/transport/can/media/candump/_candump.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def close(self) -> None:
self._f.close()
self._thread, thd = None, self._thread
assert thd is not None
thd.join(timeout=1)
try:
thd.join(timeout=1)
except RuntimeError:
pass

@property
def _is_closed(self) -> bool:
Expand Down
10 changes: 8 additions & 2 deletions pycyphal/transport/can/media/pythoncan/_pythoncan.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,15 @@ def close(self) -> None:
self._closed = True
try:
self._tx_queue.put(None)
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
try:
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
except RuntimeError:
pass
if self._maybe_thread is not None:
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
try:
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
except RuntimeError:
pass
self._maybe_thread = None
finally:
try:
Expand Down
5 changes: 4 additions & 1 deletion pycyphal/transport/can/media/socketcan/_socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def close(self) -> None:
if self._ctl_main.fileno() >= 0: # Ignore if already closed.
self._ctl_main.send(b"stop") # The actual data is irrelevant, we just need it to unblock the select().
if self._maybe_thread:
self._maybe_thread.join(timeout=_SELECT_TIMEOUT)
try:
self._maybe_thread.join(timeout=_SELECT_TIMEOUT)
except RuntimeError:
pass
self._maybe_thread = None
finally:
self._sock.close() # These are expected to be idempotent.
Expand Down
10 changes: 8 additions & 2 deletions pycyphal/transport/can/media/socketcand/_socketcand.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ def close(self) -> None:
self._closed = True
try:
self._tx_queue.put(None)
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
try:
self._tx_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
except RuntimeError:
pass
if self._maybe_thread is not None:
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
try:
self._maybe_thread.join(timeout=self._MAXIMAL_TIMEOUT_SEC * 10)
except RuntimeError:
pass
self._maybe_thread = None
finally:
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/demo/_demo_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def _unittest_slow_demo_app(
assert hb.health.value == hb.health.NOMINAL
assert hb.mode.value == hb.mode.OPERATIONAL
assert num_heartbeats <= hb.uptime <= 300
assert prev_hb_transfer[0].uptime <= hb.uptime <= prev_hb_transfer[0].uptime + 1
assert prev_hb_transfer[0].uptime <= hb.uptime <= prev_hb_transfer[0].uptime + 2 # +2 due to aliasing
assert transfer.transfer_id == prev_hb_transfer[1].transfer_id + 1
prev_hb_transfer = hb_transfer
num_heartbeats += 1
Expand Down
1 change: 1 addition & 0 deletions tests/transport/can/media/_pythoncan.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def _unittest_can_pythoncan_iface_name() -> None:
# multiple colons are allowed in interface names, only the first one is split
media = PythonCANMedia("virtual:0:0", 1_000_000)
assert media.interface_name == "virtual:0:0"
media.close()


def _unittest_can_pythoncan_errors() -> None:
Expand Down

0 comments on commit 765ab8d

Please sign in to comment.