From 1a92ebc0388ab2d50b8bebedee48a3de7af6e16d Mon Sep 17 00:00:00 2001 From: flo47663 Date: Fri, 13 Dec 2024 16:41:48 +0100 Subject: [PATCH] feat(UnitTests): fix unit tests for latest EE changes (Client Timeout) --- tests/test_helpers/util/observer_client.py | 5 +++-- .../check_control_interface/check_assignment.py | 4 ++-- .../check_default_assignment_agent.py | 12 ++++++------ .../check_execution_client.py | 2 +- .../check_queue_interaction.py | 2 +- .../check_control_interface/check_service_call.py | 2 +- .../check_control_interface/check_target_server.py | 2 +- .../check_dispatcher/check_service_callbacks.py | 4 ++-- .../check_service_input_filtering.py | 2 +- tests/unit_tests/run_unit_tests.py | 2 ++ 10 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/test_helpers/util/observer_client.py b/tests/test_helpers/util/observer_client.py index b66e89a..00ab5b2 100644 --- a/tests/test_helpers/util/observer_client.py +++ b/tests/test_helpers/util/observer_client.py @@ -13,10 +13,11 @@ class ObserverClient: def __init__(self): self.event_received = False + self.timeout = 4 async def observer_client(self, tar_server_url, iteration_time, service_browse_name): - async with Client(url=tar_server_url) as client: - target_server_list = TargetServerList(None, iteration_time) + async with Client(url=tar_server_url, timeout = self.timeout) as client: + target_server_list = TargetServerList(None, iteration_time, self.timeout) target_server = await target_server_list.get_target_server(tar_server_url, service_browse_name) handler = SubHandler(client, tar_server_url, True) event_subscription = ServiceEvents(client, iteration_time, handler, target_server.event_node) diff --git a/tests/unit_tests/check_control_interface/check_assignment.py b/tests/unit_tests/check_control_interface/check_assignment.py index 7b03467..89f29c5 100644 --- a/tests/unit_tests/check_control_interface/check_assignment.py +++ b/tests/unit_tests/check_control_interface/check_assignment.py @@ -33,10 +33,10 @@ async def check_static_assignment(self,custom_data_types = None, env = DockerCom capa, _ = self.create_structures(custom_data_types, "ResourceAssignment", {"job_resource":"opc.tcp://service_server:4080"}, "Milling_Capabilities", {"test_numeric": 5, "test_boolean": False}) - target_server_list = TargetServerList(None, iteration_time) + target_server_list = TargetServerList(None, iteration_time, 4) target_server = await target_server_list.get_target_server(server_url, service_browse_name) #create the assignment class - assign_agent = AssignAgent(None) + assign_agent = AssignAgent(None, 4) #assign without existing target resource target_agent = await assign_agent.allocate_job_to_agent("Get", [[],[]], "opc.tcp://localhost:8000", None, custom_data_types) self.assertEqual(target_agent, None) diff --git a/tests/unit_tests/check_control_interface/check_default_assignment_agent.py b/tests/unit_tests/check_control_interface/check_default_assignment_agent.py index 62e55bc..0ae9f0b 100644 --- a/tests/unit_tests/check_control_interface/check_default_assignment_agent.py +++ b/tests/unit_tests/check_control_interface/check_default_assignment_agent.py @@ -20,12 +20,12 @@ async def check_static_assignment(self, env = DockerComposeEnvironment(["Device_ service_browse_name = "Gluing" server_url = "opc.tcp://localhost:8000" filter_agent_input = [service_browse_name, ["None"], ["None"]] - a_agent = AssignAgent(True) + a_agent = AssignAgent(True, 4) async with Client(url=server_url) as client: agent_list = await a_agent.get_agents_from_the_device_registry(client, filter_agent_input) await client.disconnect() self.assertIsNot(None, agent_list) - target_agent = await DefaultAssignmentAgent(server_url, agent_list).find_target_resource() + target_agent = await DefaultAssignmentAgent(server_url, agent_list, 4).find_target_resource() self.assertEqual(str(target_agent), "opc.tcp://service_server:4061") env.stop_docker_compose() #from multiple resources @@ -37,7 +37,7 @@ async def check_dynamic_assignment(self, env = DockerComposeEnvironment(["Device target_server_list = ["opc.tcp://localhost:4080", "opc.tcp://localhost:4082"] iteration_time = 0.001 filter_agent_input = [service_browse_name, ["None"], ["None"]] - a_agent = AssignAgent(True) + a_agent = AssignAgent(True, 4) async with Client(url=server_url) as client: agent_list = await a_agent.get_agents_from_the_device_registry(client, filter_agent_input) await client.disconnect() @@ -48,7 +48,7 @@ async def check_dynamic_assignment(self, env = DockerComposeEnvironment(["Device for i, j in zip(elements, target_server_list): for z in range(i): async with Client(url=j) as client: - t_server_list = TargetServerList(None, iteration_time) + t_server_list = TargetServerList(None, iteration_time, 4) target_server = await t_server_list.get_target_server(j, service_browse_name) queue = TargetServerQueue(iteration_time, client) service_uuid = str(uuid.uuid4()) @@ -58,7 +58,7 @@ async def check_dynamic_assignment(self, env = DockerComposeEnvironment(["Device await client.disconnect() time.sleep(3) #now check the assignment, opc.tcp://localhost:4080 should be assigned, since it has only 2 elements - target_agent = await DefaultAssignmentAgent(server_url, agent_list).find_target_resource() + target_agent = await DefaultAssignmentAgent(server_url, agent_list, 4).find_target_resource() self.assertEqual(str(a_agent.convert_to_custom_url(target_agent, "opc.tcp://localhost:")), target_server_list[0]) #next, remove the elements from server opc.tcp://localhost:4082 and re-assign async with Client(url=target_server_list[1]) as client: @@ -68,7 +68,7 @@ async def check_dynamic_assignment(self, env = DockerComposeEnvironment(["Device await queue.client_remove_queue_element(target_server, service_ids[i+2], client_ids[i+2]) await client.disconnect() time.sleep(3) - target_agent = await DefaultAssignmentAgent(server_url, agent_list).find_target_resource() + target_agent = await DefaultAssignmentAgent(server_url, agent_list, 4).find_target_resource() self.assertEqual(str(a_agent.convert_to_custom_url(target_agent, "opc.tcp://localhost:")), target_server_list[1]) env.stop_docker_compose() await asyncio.sleep(10) diff --git a/tests/unit_tests/check_control_interface/check_execution_client.py b/tests/unit_tests/check_control_interface/check_execution_client.py index b09a57d..3a374ef 100644 --- a/tests/unit_tests/check_control_interface/check_execution_client.py +++ b/tests/unit_tests/check_control_interface/check_execution_client.py @@ -33,7 +33,7 @@ async def check_execution_client(self, custom_data_types = None): if custom_data_types == None: custom_data_types = server_instance.custom_data_types #server, server_instance, service_execution_list, target_server_list, device_registry_url, assignment_agent_url, docker, iteration_time, log_info): - ci = ControlInterface(server_instance, server, ExecutionList(), TargetServerList(server_instance, iteration_time), None, None, True, iteration_time, True) + ci = ControlInterface(server_instance, server, ExecutionList(), TargetServerList(server_instance, iteration_time, 4), None, None, True, iteration_time, True, 4) #client list should be emtpy self.assertEqual(len(ci.client_dict["Client"]), 0) #init and check default clients diff --git a/tests/unit_tests/check_control_interface/check_queue_interaction.py b/tests/unit_tests/check_control_interface/check_queue_interaction.py index 3e05b28..e59b5e0 100644 --- a/tests/unit_tests/check_control_interface/check_queue_interaction.py +++ b/tests/unit_tests/check_control_interface/check_queue_interaction.py @@ -23,7 +23,7 @@ async def queue_interaction(self, env = DockerComposeEnvironment(["Device_Regist iteration_time = 0.001 # start client, connect to server and explore the server's namespace async with (Client(url=server_url) as client): - target_server_list = TargetServerList(None, iteration_time) + target_server_list = TargetServerList(None, iteration_time, 4) target_server = await target_server_list.get_target_server(server_url, service_browse_name) queue = TargetServerQueue(iteration_time, client) id_dict = Identifier() diff --git a/tests/unit_tests/check_control_interface/check_service_call.py b/tests/unit_tests/check_control_interface/check_service_call.py index ecfcd04..9bd185b 100644 --- a/tests/unit_tests/check_control_interface/check_service_call.py +++ b/tests/unit_tests/check_control_interface/check_service_call.py @@ -24,7 +24,7 @@ async def check_service_call_from_literal(self, env = DockerComposeEnvironment([ iteration_time = 0.001 # start client, connect to server and explore the server's namespace async with Client(url=server_url) as client: - target_server_list = TargetServerList(None, iteration_time) + target_server_list = TargetServerList(None, iteration_time, 4) target_server = await target_server_list.get_target_server(server_url, service_browse_name) target_server.Input_Arguments, target_server.Output_Arguments = await CheckServiceMethodArguments().browse_method_arguments( target_server.service_node, client, *await target_server.browse_result_data_type_nodes(client), diff --git a/tests/unit_tests/check_control_interface/check_target_server.py b/tests/unit_tests/check_control_interface/check_target_server.py index f07b0e3..df1ffd0 100644 --- a/tests/unit_tests/check_control_interface/check_target_server.py +++ b/tests/unit_tests/check_control_interface/check_target_server.py @@ -19,7 +19,7 @@ async def check_server_browsing(self, env = DockerComposeEnvironment(["Device_Re async with Client(url="opc.tcp://localhost:4080") as client: #add a server to the target server list and check if it was browsed correctly - target_server = await TargetServerList(None, 0.001).get_target_server("opc.tcp://localhost:4080", + target_server = await TargetServerList(None, 0.001, 4).get_target_server("opc.tcp://localhost:4080", "GetPartsFromWarehouse") #check browsenames for browsename, value in zip([target_server.implementation, target_server.explored, target_server.url, diff --git a/tests/unit_tests/check_dispatcher/check_service_callbacks.py b/tests/unit_tests/check_dispatcher/check_service_callbacks.py index ff1cd87..dc29c71 100644 --- a/tests/unit_tests/check_dispatcher/check_service_callbacks.py +++ b/tests/unit_tests/check_dispatcher/check_service_callbacks.py @@ -37,7 +37,7 @@ async def check_service_callback_with_default_task(self, custom_server_types = N async with server: cb = DispatcherCallbackFunctions(server, server_instance, EngineOpcUaDataConverter(), OpcUaEngineDataConverter()) - cb.add_control_interface(ControlInterface(server_instance, server, cb.service_execution_list, TargetServerList(server_instance, iteration_time), dr_url, None, "opc.tcp://localhost:", iteration_time, True)) + cb.add_control_interface(ControlInterface(server_instance, server, cb.service_execution_list, TargetServerList(server_instance, iteration_time, 4), dr_url, None, "opc.tcp://localhost:", iteration_time, True, 4)) #start a client to observe the service call observer = ObserverClient() observer.start_observer_client_thread("opc.tcp://localhost:4071", iteration_time, service_name) @@ -89,7 +89,7 @@ async def check_service_callback_with_ordinary_task(self, custom_server_types = async with server: cb = DispatcherCallbackFunctions(server, server_instance, EngineOpcUaDataConverter(), OpcUaEngineDataConverter()) - cb.add_control_interface(ControlInterface(server_instance, server, cb.service_execution_list, TargetServerList(server_instance, iteration_time), dr_url, None, "opc.tcp://localhost:", iteration_time, True)) + cb.add_control_interface(ControlInterface(server_instance, server, cb.service_execution_list, TargetServerList(server_instance, iteration_time, 4), dr_url, None, "opc.tcp://localhost:", iteration_time, True, 4)) #start a client to observe the service call observer = ObserverClient() observer.start_observer_client_thread("opc.tcp://localhost:4071", iteration_time, service_name) diff --git a/tests/unit_tests/check_dispatcher/check_service_input_filtering.py b/tests/unit_tests/check_dispatcher/check_service_input_filtering.py index dde8c06..e67baa5 100644 --- a/tests/unit_tests/check_dispatcher/check_service_input_filtering.py +++ b/tests/unit_tests/check_dispatcher/check_service_input_filtering.py @@ -43,7 +43,7 @@ async def filter_from_literal_input(self, custom_server_types = None, env = Dock #check for a static resource assignment self.assertEqual(cb.callback_helpers.check_for_target_type(server_instance, input_parameter, "ResourceAssignment"), "opc.tcp://service_server:4080") #check for capabilities - self.assertEqual(await AssignAgent(custom_server_types).create_filter_agent_input_arguments([["test_name"], input_parameter], service_name, custom_server_types), ['Milling', ['test_numeric'], ['5']]) + self.assertEqual(await AssignAgent(custom_server_types, 4).create_filter_agent_input_arguments([["test_name"], input_parameter], service_name, custom_server_types), ['Milling', ['test_numeric'], ['5']]) #check for static assignment agent self.assertEqual(cb.callback_helpers.check_for_target_type(server_instance, input_parameter, "AssignmentAgent"), "opc.tcp://assignment_agent:10000") # check for static device_registry diff --git a/tests/unit_tests/run_unit_tests.py b/tests/unit_tests/run_unit_tests.py index 200aef9..298abab 100644 --- a/tests/unit_tests/run_unit_tests.py +++ b/tests/unit_tests/run_unit_tests.py @@ -20,11 +20,13 @@ class ExecuteUnitTests(unittest.TestCase): def test_run_unit_tests(self): + print("start tests") env = DockerComposeEnvironment(["Device_Registry", "Service_Server"]) custom_type_definitions = RunExecutionEngineLogicTests().run_execution_engine_logic_tests(env = env) custom_type_definitions = RunControlInterfaceTests().run_control_interface_tests(custom_data_types=custom_type_definitions, env = env) custom_type_definitions = RunDispatcherTests().run_dispatcher_tests(custom_data_types = custom_type_definitions, env = env) env.stop_docker_compose() + print("completed tests") if __name__ == "__main__":