SIENTIAPDE-1314
Refactor IngestorManager and OpcManager for improved server management - Introduced a new method `remove_server` in IngestorManager to encapsulate server removal logic, enhancing code clarity and reusability. - Updated `update_opc_servers` to utilize the new `remove_server` method for better maintainability. - Refactored security settings in OpcManager to use direct attribute assignments instead of method calls, streamlining the code. - Adjusted unit tests to reflect changes in the IngestorManager and OpcManager, ensuring proper asynchronous behavior and mocking.
This commit is contained in:
@@ -451,7 +451,11 @@ async def test_subscribe_to_tags(ingestor_manager):
|
||||
ingestor_manager.manage_server = AsyncMock(side_effect=[0, 1, 2])
|
||||
ingestor_manager.managed_tags = {'slot1': MagicMock(), 'slot2': MagicMock()}
|
||||
|
||||
ingestor_manager.opc_managers = {'server1': AsyncMock(), 'server2': AsyncMock()}
|
||||
ingestor_manager.opc_managers = {
|
||||
'server1': AsyncMock(),
|
||||
'server2': AsyncMock(),
|
||||
'server3': AsyncMock(),
|
||||
}
|
||||
ingestor_manager.subscriptions = {'server1': AsyncMock()}
|
||||
tags = {
|
||||
'slot1': {
|
||||
@@ -509,21 +513,22 @@ async def test_check_opc_servers_integrity_all_healthy(metrics, ingestor_manager
|
||||
)
|
||||
|
||||
|
||||
def test_check_opc_servers_integrity_server_lost(ingestor_manager):
|
||||
@mark.asyncio
|
||||
async def test_check_opc_servers_integrity_server_lost(ingestor_manager):
|
||||
# Setup mock OPC manager that will be lost
|
||||
opc_manager = MagicMock()
|
||||
opc_manager = AsyncMock()
|
||||
opc_manager.check_cycles.return_value = None
|
||||
opc_manager.check_opc_listenning.return_value = True # Server is lost
|
||||
opc_manager.config = {'config': 'config1'}
|
||||
|
||||
ingestor_manager.opc_managers = {'server1': opc_manager}
|
||||
|
||||
# Mock the initialize_opc_from_config method to return a new manager
|
||||
new_manager = MagicMock()
|
||||
ingestor_manager.initialize_opc_from_config = MagicMock(return_value=new_manager)
|
||||
ingestor_manager.managed_tags = {'slot1': MagicMock()}
|
||||
|
||||
# Call the method
|
||||
ingestor_manager.check_opc_servers_integrity()
|
||||
await ingestor_manager.check_opc_servers_integrity()
|
||||
|
||||
assert 'server1' not in ingestor_manager.opc_managers
|
||||
ingestor_manager.managed_tags['slot1'].pop.assert_called_once_with('server1', None)
|
||||
|
||||
|
||||
def test_check_opc_servers_integrity_server_lost_with_tags(ingestor_manager):
|
||||
|
||||
@@ -105,7 +105,7 @@ async def test_shutdown_error(opc_manager):
|
||||
async def test_set_security_success(opc_manager):
|
||||
await opc_manager.set_security()
|
||||
|
||||
opc_manager.client.set_application_uri.assert_called_once_with(opc_manager.server_uri)
|
||||
assert opc_manager.client.application_uri == opc_manager.server_uri
|
||||
|
||||
opc_manager.client.set_security.assert_called_once_with(
|
||||
SecurityPolicyBasic256,
|
||||
@@ -114,8 +114,8 @@ async def test_set_security_success(opc_manager):
|
||||
server_certificate=opc_manager.server_cert_path,
|
||||
)
|
||||
|
||||
opc_manager.client.set_secure_channel_timeout.assert_called_once_with(10000000)
|
||||
opc_manager.client.set_session_timeout.assert_called_once_with(10000000)
|
||||
assert opc_manager.client.secure_channel_timeout == 10000000
|
||||
assert opc_manager.client.session_timeout == 10000000
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user