SIENTIAPDE-1312

Enhance OpcManager to accept subscription period from configuration

- Updated OpcManager to include subscription_period_ms as a parameter for better configurability.
- Refactored create_subscription method to utilize the new subscription period parameter.
- Adjusted unit tests to reflect changes in subscription handling and ensure correct functionality.
This commit is contained in:
vitor-aignosi
2025-10-20 12:41:05 -03:00
parent 64a1a14a8b
commit 47b3159e71
3 changed files with 33 additions and 8 deletions

View File

@@ -50,6 +50,7 @@ def raw_opc_manager(mock_metrics):
name='TestConnector',
url='opc.tcp://localhost:4840',
data_manager=MagicMock(),
subscription_period_ms=1000,
logger=MagicMock(),
server_uri='opc.tcp://localhost:4840',
notification_handler=MagicMock(),
@@ -223,24 +224,26 @@ async def test_create_subscription_no_client(raw_opc_manager):
@mark.asyncio
async def test_create_subscription_success_has_period(opc_manager):
await opc_manager.create_subscription('sub1', 1000)
await opc_manager.create_subscription('sub1')
opc_manager.client.create_subscription.assert_called_once_with(1000, opc_manager)
opc_manager.client.create_subscription.assert_called_once_with(
opc_manager.subscription_period_ms, opc_manager)
assert opc_manager.subscriptions['sub1'] is not None
@mark.asyncio
async def test_create_subscription_success_no_period(opc_manager):
await opc_manager.create_subscription('sub1', None)
await opc_manager.create_subscription('sub1')
opc_manager.client.create_subscription.assert_called_once_with(500, opc_manager)
opc_manager.client.create_subscription.assert_called_once_with(
opc_manager.subscription_period_ms, opc_manager)
assert opc_manager.subscriptions['sub1'] is not None
@patch('ingestor.managers.opc_manager.metrics')
@mark.asyncio
async def test_create_subscription_with_metrics(metrics, opc_manager):
await opc_manager.create_subscription('sub1', 1000)
await opc_manager.create_subscription('sub1')
metrics.OPC_SUBSCRIPTIONS_CREATED.labels.assert_called_once_with(
pod_id=opc_manager.pod_id, server_name=opc_manager.name, slot_name='sub1'
@@ -572,6 +575,7 @@ def test_init_metrics_calls_correct_metric_methods(metrics):
name='TestInitConnector',
url='opc.tcp://init.test:4840',
data_manager=MagicMock(),
subscription_period_ms=1000,
logger=MagicMock(),
server_uri='opc.tcp://init.test:4840/uri',
notification_handler=MagicMock(),