Skip to content

Commit

Permalink
feat(UnitTests): fix unit tests for latest EE changes (Client Timeout)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianDue committed Dec 13, 2024
1 parent 0336735 commit 1a92ebc
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions tests/test_helpers/util/observer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/check_control_interface/check_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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())
Expand All @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/check_dispatcher/check_service_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 1a92ebc

Please sign in to comment.