Files
sientia-dataops-opc-ingestor/tests/functional/test_single_node.py
vitor-aignosi 4208412eca SIENTIAPDE-988
Add temporary functiontal tests, that must be removed soon.

Refactor tests: Remove outdated resource manager tests and add functional tests with Docker and Kafka integration

- Deleted existing unit tests for ResourceManager.
- Introduced new functional tests for single node operations with Redis and Kafka.
- Added Docker Compose setup for test environment.
- Implemented fixtures for Redis and Kafka consumers.
- Created comprehensive tests for data publishing and slot management.
- Added unit tests for DataManager and IngestorManager with mocked dependencies.
- Included tests for OpcManager covering connection, subscription, and data change notifications.
2025-04-22 17:56:54 -03:00

119 lines
3.7 KiB
Python

import json
import subprocess
from time import sleep
from tests.functional.conftest import kafka_searcher
new_data = {
"slot:opc_tags:1": {
"server1": {
"name": "server1",
"url": "opc.tcp://simulator:4840",
"server_uri": "http://opcua-server.simulator",
"tags": {
'ns=2;i=2': {
'tag_name': 'Counter',
'frequency': 1000,
'topics': [],
},
'ns=2;i=3': {
'tag_name': 'Rollout',
'frequency': 1000,
"topics": [],
},
'ns=2;i=4': {
'tag_name': 'Square',
'frequency': 1000,
"topics": [],
},
}
}
},
"slot:opc_tags:2": {
"server2": {
"name": "server2",
"url": "opc.tcp://simulator:4840",
"server_uri": "http://opcua-server.simulator",
"tags": {
'ns=2;i=2': {
'tag_name': 'Counter',
'frequency': 1000,
'topics': [],
},
'ns=2;i=3': {
'tag_name': 'Rollout',
'frequency': 1000,
"topics": [],
},
'ns=2;i=4': {
'tag_name': 'Square',
'frequency': 1000,
"topics": [],
},
}
}
}
}
def test_simple(redis_client):
new_data['slot:opc_tags:1']['server1']['tags']['ns=2;i=2']['topics'] = [
'test_topic_1']
redis_client.set("slot:opc_tags:1",
json.dumps(new_data['slot:opc_tags:1']))
sleep(20) # Espera o Ingestor processar os dados
# Check if lease is in Redis
assert redis_client.get("lease:opc_tags:1") == 'ingestor'
assert redis_client.get("heartbeat:ingestor:ingestor") == '1'
# Check if data is in Kafka
kafka = next(kafka_searcher('test_topic_1'))
sleep(1)
messages = kafka.poll(timeout_ms=10000)
assert messages, "Expected messages in Kafka, but got none."
def test_simple_double_slot(redis_client):
new_data['slot:opc_tags:1']['server1']['tags']['ns=2;i=2']['topics'] = [
'test_topic_double_slot1']
redis_client.set("slot:opc_tags:1",
json.dumps(new_data['slot:opc_tags:1']))
sleep(20) # Espera o Ingestor processar os dados
assert redis_client.get("lease:opc_tags:1") == 'ingestor'
assert redis_client.get("heartbeat:ingestor:ingestor") == '1'
# Check if data is in Kafka
kafka1 = next(kafka_searcher('test_topic_double_slot1'))
messages = kafka1.poll(timeout_ms=10000)
assert messages, "Expected messages in test_topic_double_slot1, but got none."
new_data['slot:opc_tags:2']['server2']['tags']['ns=2;i=2']['topics'] = [
'test_topic_double_slot2']
redis_client.set("slot:opc_tags:2",
json.dumps(new_data['slot:opc_tags:2']))
sleep(20) # Espera o Ingestor processar os dados
# Check if lease is in Redis
assert redis_client.get("lease:opc_tags:2") == 'ingestor'
assert redis_client.get("lease:opc_tags:1") == 'ingestor'
assert redis_client.get("heartbeat:ingestor:ingestor") == '1'
# Check if data is in Kafka
kafka2 = next(kafka_searcher('test_topic_double_slot2'))
messages = kafka2.poll(timeout_ms=10000)
assert messages, "Expected messages in test_topic_double_slot2, but got none."
messages = kafka1.poll(timeout_ms=10000)
assert messages, "Expected messages in test_topic_double_slot1, but got none."