Skip to content
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

Remove extra connect in python_microservice #1400

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ def connect(self):
pass # We want to report any connect errors, not disconnect in this case
raise error

self.interface.connect()
self.interface.state = "CONNECTED"
if self.interface_or_router == "INTERFACE":
InterfaceStatusModel.set(self.interface.as_json(), queued=True, scope=self.scope)
Expand Down
30 changes: 11 additions & 19 deletions openc3/python/test/microservices/test_interface_microservice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 OpenC3, Inc.
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down Expand Up @@ -44,11 +44,14 @@ def __init__(self, hostname="default", port=12345):
self.hostname = hostname
self.port = port
self._connected = False
self.connect_count = 0
self.disconnect_count = 0
self.disconnect_delay = 0
self.connect_calls = 0
super().__init__()

def connect(self):
self.connect_count += 1
time.sleep(0.001)
super().connect()
self.data = b"\x00"
Expand Down Expand Up @@ -105,9 +108,7 @@ def setUp(self):
time.sleep(0.01) # Allow the write to happen

mock_system = Mock(System)
self.patch_system = patch(
"openc3.system.system.System", return_value=mock_system
)
self.patch_system = patch("openc3.system.system.System", return_value=mock_system)
self.mock_system = self.patch_system.start()
self.addCleanup(self.patch_system.stop)

Expand Down Expand Up @@ -227,9 +228,7 @@ def test_handles_exceptions_while_reading(self):
time.sleep(0.1)
self.assertIn(TestInterfaceMicroservice.CONNECTING_MSG, stdout.getvalue())
self.assertIn(TestInterfaceMicroservice.CONN_SUCCESS_MSG, stdout.getvalue())
self.assertIn(
"Connection Lost: RuntimeError('test-error')", stdout.getvalue()
)
self.assertIn("Connection Lost: RuntimeError('test-error')", stdout.getvalue())

MyInterface.read_interface_raise = False
time.sleep(0.1) # Allow to reconnect
Expand All @@ -253,11 +252,10 @@ def test_connect_handles_parameters(self):
self.assertIn(TestInterfaceMicroservice.CONN_SUCCESS_MSG, stdout.getvalue())
all_interfaces = InterfaceStatusModel.all(scope="DEFAULT")
self.assertEqual(all_interfaces["INST_INT"]["state"], "CONNECTED")
self.assertEqual(im.interface.connect_count, 1)

for stdout in capture_io():
InterfaceTopic.connect_interface(
"INST_INT", "test-host", 54321, scope="DEFAULT"
)
InterfaceTopic.connect_interface("INST_INT", "test-host", 54321, scope="DEFAULT")
time.sleep(0.5)
self.assertIn("Connection Lost", stdout.getvalue())
self.assertIn(TestInterfaceMicroservice.CONNECTING_MSG, stdout.getvalue())
Expand Down Expand Up @@ -371,14 +369,10 @@ def test_supports_inject_tlm(self):
scope="DEFAULT",
)
time.sleep(0.1)
for _, _, msg_hash, _ in Topic.read_topics(
["DEFAULT__TELEMETRY__{INST}__HEALTH_STATUS"]
):
for _, _, msg_hash, _ in Topic.read_topics(["DEFAULT__TELEMETRY__{INST}__HEALTH_STATUS"]):
packet = System.telemetry.packet("INST", "HEALTH_STATUS")
packet.stored = ConfigParser.handle_true_false(msg_hash[b"stored"].decode())
packet.received_time = from_nsec_from_epoch(
int(msg_hash[b"received_time"].decode())
)
packet.received_time = from_nsec_from_epoch(int(msg_hash[b"received_time"].decode()))
packet.received_count = int(msg_hash[b"received_count"].decode())
packet.buffer = msg_hash[b"buffer"]
self.assertEqual(packet.read("TEMP1", "RAW"), 10)
Expand All @@ -396,9 +390,7 @@ def test_supports_interface_cmd(self):
all_interfaces = InterfaceStatusModel.all(scope="DEFAULT")
self.assertEqual(all_interfaces["INST_INT"]["state"], "CONNECTED")

InterfaceTopic.interface_cmd(
"INST_INT", "DO_THE_THING", "PARAM1", 2, scope="DEFAULT"
)
InterfaceTopic.interface_cmd("INST_INT", "DO_THE_THING", "PARAM1", 2, scope="DEFAULT")
time.sleep(0.5)
self.assertEqual("DO_THE_THING", im.interface.interface_cmd_name)
self.assertEqual(("PARAM1", 2), im.interface.interface_cmd_args)
Expand Down
Loading