Skip to content

Commit ed6c345

Browse files
committed
fix: retry init and test
1 parent a6776c4 commit ed6c345

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

.github/workflows/test-pr.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ jobs:
1919
- name: Install dependencies
2020
run: |
2121
python -m pip install --upgrade pip
22-
pip install -r requirements.txt
23-
pip install pytest-cov
22+
pip install -r requirements.txt -r requirements-dev.txt
2423
2524
- name: Run tests with coverage
2625
run: |

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
pytest
22
pytest-mock
3+
pytest-asyncio
4+
pytest-cov

signalduino/controller.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ def _reset_device(self) -> None:
199199
# Wait briefly to ensure port is released/device resets
200200
threading.Event().wait(2.0)
201201
self.connect()
202-
self.initialize()
202+
# Manuell die Initialisierung starten, ohne die Zähler zurückzusetzen.
203+
# XQ sollte direkt gesendet werden.
204+
self._send_xq()
205+
self._start_init()
203206
except Exception as e:
204207
self.logger.error("Failed to reset device: %s", e)
205208

tests/test_controller.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def side_effect(*args, **kwargs):
156156
nonlocal call_count
157157
call_count += 1
158158
payload = kwargs.get("payload") or args[0] if args else None
159-
159+
160160
if payload == "XQ":
161161
return None
162162
if payload == "V":
@@ -165,7 +165,8 @@ def side_effect(*args, **kwargs):
165165
return "V 3.5.0-dev SIGNALduino"
166166
return None
167167

168-
controller.send_command = Mock(side_effect=side_effect)
168+
mocked_send_command = Mock(side_effect=side_effect)
169+
controller.commands._send = mocked_send_command
169170

170171
# Use very short intervals for testing by patching the imported constants in the controller module
171172
import signalduino.controller
@@ -178,7 +179,7 @@ def side_effect(*args, **kwargs):
178179

179180
try:
180181
controller.initialize()
181-
time.sleep(1.5) # Wait for timers and retries
182+
time.sleep(3.0) # Wait for timers and retries (increased from 1.5s due to potential race condition)
182183

183184
# Verify calls:
184185
# 1. XQ
@@ -189,7 +190,8 @@ def side_effect(*args, **kwargs):
189190
# Note: Depending on timing and implementation details, call count might vary slighty
190191
# but we expect at least XQ, failed V, successful V, XE.
191192

192-
calls = [c.kwargs.get('payload') or c.args[0] for c in controller.send_command.call_args_list]
193+
calls = [c.kwargs.get('payload') or c.args[0] for c in mocked_send_command.call_args_list]
194+
193195
assert "XQ" in calls
194196
assert calls.count("V") >= 2
195197
assert "XE" in calls

0 commit comments

Comments
 (0)