From 413c28a3f94b1774ec03a6aa1e3b4f61f1e70dd0 Mon Sep 17 00:00:00 2001 From: Emily Ragan Date: Fri, 23 Oct 2026 13:36:41 -0600 Subject: [PATCH] test(cmd-api): wait for handler thread before sending commands The interface cmd handler thread starts reading from the newest message the first time it reads a topic. setUp only slept 1ms, so a command sent before then was never seen or acked, causing a 30s ack timeout flake. Poll until the thread has recorded its offset for the INST cmd topic. Co-Authored-By: Claude Sonnet 5.5 --- openc3/python/test/api/test_cmd_api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openc3/python/test/api/test_cmd_api.py b/openc3/python/test/api/test_cmd_api.py index 14d68076af..821b2442e5 100644 --- a/openc3/python/test/api/test_cmd_api.py +++ b/openc3/python/test/api/test_cmd_api.py @@ -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") + time.sleep(0.001) def tearDown(self): self.icht.graceful_kill()