SIENTIAPDE-1312

Refactor OpcManager connection error handling and enhance unit tests

- Simplified error handling during connection attempts in OpcManager by removing redundant disconnection logic.
- Updated unit tests to include subscription_period_ms in server configuration and adjusted connection assertions to include a timeout parameter.
- Added new tests for disconnection fallback functionality to ensure robust error handling during disconnect attempts.
This commit is contained in:
vitor-aignosi
2025-10-20 17:08:40 -03:00
parent aaa8d00f56
commit 3eacf27faf
3 changed files with 36 additions and 43 deletions

View File

@@ -210,19 +210,8 @@ class OpcManager(BaseActivity):
).set(1)
self.logger.info(f'Connection to {self.name} successful.')
except Exception as e:
try:
await self.disconnect()
except Exception as internal_e:
self.logger.error(f'And error occurred while creating connection from {self.name}, and an exception occurred while disconnecting: {internal_e}')
await self.disconnect()
del self.client
self.client = None
metrics.OPC_CONNECTION_STATUS.labels(
pod_id=self.pod_id, server_name=self.name, server_url=self.url
).set(0)
metrics.OPC_CONNECTIONS_FAILED.labels(pod_id=self.pod_id, server_name=self.name).inc()
self.logger.error(f'Failed to connect to {self.name}: {e}')
raise
async def create_subscription(self, name: str):