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()