Repository navigation
test(cmd-api): wait for handler thread before sending commands #4140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| from openc3.models.microservice_model import MicroserviceModel | ||
| from openc3.packets.packet import Packet | ||
| from openc3.top_level import HazardousError | ||
| from openc3.utilities.store import EphemeralStore | ||
| from test.test_helper import capture_io, mock_redis, setup_system | ||
|
|
||
|
|
||
|
|
@@ -108,7 +109,15 @@ def xread_side_effect(*args, **kwargs): | |
|
|
||
| self.icht = InterfaceCmdHandlerThread(self.interface, None, scope="DEFAULT") | ||
| self.thread = self.icht.start() | ||
| time.sleep(0.001) | ||
| # The handler thread starts reading from the newest message the first time it reads a topic. | ||
| # Wait for it to record its offsets or a command written before then is never seen (and acked). | ||
| offsets = EphemeralStore.instance().topic_offsets | ||
| cmd_topic = "{DEFAULT__CMD}TARGET__INST" | ||
| deadline = time.time() + 5 | ||
| while cmd_topic not in offsets.get(self.thread.native_id, {}): | ||
| if time.time() > deadline: | ||
| self.fail("Interface cmd handler thread never started reading") | ||
|
Comment on lines
+118
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis
Register handler cleanup before the readiness wait. If the five-second deadline expires, Cleanups run in last-in, first-out order. Register the join first so that 🐛 Suggested fix
🤖 Prompt for AI Agents
|
||
| time.sleep(0.001) | ||
|
|
||
| def tearDown(self): | ||
| self.icht.graceful_kill() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude recommended build the same topic list receive_commands builds, then poll until every topic has an offset. Replace the cmd_topic lines with: