SIENTIAPDE-988

Refactor OpcManager initialization and unsubscribe method; enhance logging

- Removed the `initialize_from_config` method from `OpcManager` class and adjusted the constructor to handle configuration directly.
- Improved the `unsubscribe` method to include detailed logging for non-existent subscriptions.
- Updated tests in `test_opc_manager.py` to reflect changes in the `OpcManager` class.
- Commented out Docker-related fixtures in `conftest.py` for potential future use.
- Enhanced test coverage in `test_single_node.py` and `test_data_manager.py` with additional scenarios and assertions.
- Introduced new methods in `Ingestor` and `IngestorManager` classes to manage server subscriptions and leases more effectively.
- Added new tests for `Ingestor` class to validate initialization and slot management logic.
- Implemented logging improvements across various classes to ensure better traceability of actions and errors.
This commit is contained in:
vitor-aignosi
2025-04-23 18:24:49 -03:00
parent 4208412eca
commit b9ef69a865
13 changed files with 1128 additions and 294 deletions

View File

@@ -1,4 +1,5 @@
import json
from datetime import datetime
from unittest.mock import MagicMock, patch
from pytest import fixture
@@ -56,6 +57,10 @@ def opc_manager_subscribed(opc_manager):
return opc_manager
def test___str__(opc_manager):
assert str(opc_manager) == 'OpcManager(name=TestConnector, url=opc.tcp://localhost:4840, server_uri=opc.tcp://localhost:4840)\nnodes={}, subscriptions={}'
def test_set_security_success(opc_manager):
opc_manager.set_security()
@@ -160,13 +165,11 @@ def test_subscribe_success(opc_manager_subscribed):
def test_unsubscribe_no_subscription(opc_manager):
try:
opc_manager.unsubscribe('sub1')
except ValueError as e:
assert str(
e) == "Subscription not created. Call create_subscription first."
else:
assert False, "ValueError not raised"
opc_manager.unsubscribe('sub1')
opc_manager.logger.warning.assert_called_once_with(
"Subscription 'sub1' not found. Cannot unsubscribe.")
assert opc_manager.subscriptions.get('sub1') is None
def test_unsubscribe_success(opc_manager_subscribed):
@@ -181,7 +184,7 @@ def test_disconnect_success(opc_manager_subscribed):
opc_manager_subscribed.disconnect()
opc_manager_subscribed.subscriptions['sub1'].delete.assert_called_once()
opc_manager_subscribed.client.disconnect.assert_called_once()
assert opc_manager_subscribed.client is None
def test_disconnect_error(opc_manager_subscribed):
@@ -203,8 +206,8 @@ def test_datachange_notification(opc_manager_subscribed):
monitored_item=MagicMock(
Value=MagicMock(
Value=MagicMock(Value=42),
SourceTimestamp='2021-01-01T00:00:00'
SourceTimestamp=datetime.strptime(
'2021-01-01T00:00:00', '%Y-%m-%dT%H:%M:%S')
)))
opc_manager_subscribed.nodes = {
'ns=3;i=1001': {
@@ -224,14 +227,14 @@ def test_datachange_notification(opc_manager_subscribed):
'topic1', {
'tag': 'ns=3;i=1001',
'name': 'Counter',
'timestamp': '2021-01-01T00:00:00',
'timestamp': '2021-01-01 00:00:00',
'value': 42
})
opc_manager_subscribed.data_manager.publish.assert_any_call(
'topic2', {
'tag': 'ns=3;i=1001',
'name': 'Counter',
'timestamp': '2021-01-01T00:00:00',
'timestamp': '2021-01-01 00:00:00',
'value': 42
})
assert opc_manager_subscribed.nodes['ns=3;i=1001']['cycle_rule']['cycle_count'] == 0