fix: update search attribute keys and improve schedule handling
- Changed search attribute key from "Orchestrated" to "orchestrated" in temporal_manager.py and test cases. - Enhanced logging for schedule creation and updates in temporal_manager.py. - Updated schedule creation to use workflow_type directly instead of a hardcoded string. - Modified gather_read_tags function to use server_id instead of server_name for tag identification. - Adjusted test cases to reflect changes in server_id usage and ensure consistency across tests. - Fixed model_name retrieval in common_config to access nested models dictionary. - Updated test cases to align with new data structures and ensure accurate assertions.
This commit is contained in:
@@ -51,17 +51,20 @@ async def test_process_schedules(mock_predictions_batch, mock_scouter, formatter
|
||||
@mark.asyncio
|
||||
@patch("orchestrator.activities.formatters.gather_read_tags",
|
||||
return_value={
|
||||
"test_server_name:test_tag_address": {
|
||||
"1:test_tag_address": {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address",
|
||||
"topics": ["raw_test_schedule"]
|
||||
},
|
||||
"test_server_name2:test_tag_address2": {
|
||||
"2:test_tag_address2": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
},
|
||||
"test_server_name2:test_tag_address3": {
|
||||
"2:test_tag_address3": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address3",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
@@ -72,6 +75,7 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
input_data = {
|
||||
"opc_servers": [
|
||||
{
|
||||
"id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
@@ -80,6 +84,7 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"uri": "test_uri2"
|
||||
@@ -98,13 +103,15 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
mock_build_tag_config.assert_has_calls([
|
||||
call(
|
||||
{
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address",
|
||||
"topics": ["raw_test_schedule"]
|
||||
},
|
||||
ANY,
|
||||
{
|
||||
"test_server_name": {
|
||||
"1": {
|
||||
"id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
@@ -112,7 +119,8 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
"test_name": "test_spec"
|
||||
}
|
||||
},
|
||||
"test_server_name2": {
|
||||
"2": {
|
||||
"id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"uri": "test_uri2"
|
||||
@@ -124,13 +132,15 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
mock_build_tag_config.assert_has_calls([
|
||||
call(
|
||||
{
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
},
|
||||
ANY,
|
||||
{
|
||||
"test_server_name": {
|
||||
"1": {
|
||||
"id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
@@ -138,7 +148,8 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
"test_name": "test_spec"
|
||||
}
|
||||
},
|
||||
"test_server_name2": {
|
||||
"2": {
|
||||
"id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"uri": "test_uri2"
|
||||
@@ -150,13 +161,15 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
mock_build_tag_config.assert_has_calls([
|
||||
call(
|
||||
{
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address3",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
},
|
||||
ANY,
|
||||
{
|
||||
"test_server_name": {
|
||||
"1": {
|
||||
"id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
@@ -164,7 +177,8 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
"test_name": "test_spec"
|
||||
}
|
||||
},
|
||||
"test_server_name2": {
|
||||
"2": {
|
||||
"id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"uri": "test_uri2"
|
||||
@@ -177,12 +191,14 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
assert result == {
|
||||
"1": {
|
||||
"test_server_name": {
|
||||
"server_id": "1",
|
||||
"name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"server_uri": "test_uri",
|
||||
"test_name": "test_spec",
|
||||
"tags": {
|
||||
"test_tag_address": {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address",
|
||||
"topics": ["raw_test_schedule"]
|
||||
@@ -190,11 +206,13 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
}
|
||||
},
|
||||
"test_server_name2": {
|
||||
"server_id": "2",
|
||||
"name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"server_uri": "test_uri2",
|
||||
"tags": {
|
||||
"test_tag_address2": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
@@ -204,11 +222,13 @@ async def test_process_slots(mock_build_tag_config, mock_gather_read_tags, forma
|
||||
},
|
||||
"2": {
|
||||
"test_server_name2": {
|
||||
"server_id": "2",
|
||||
"name": "test_server_name2",
|
||||
"url": "test_url2",
|
||||
"server_uri": "test_uri2",
|
||||
"tags": {
|
||||
"test_tag_address3": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address3",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
|
||||
@@ -34,8 +34,13 @@ async def test_load_opc_slots(slot_manager):
|
||||
slot_manager.redis_client.keys.return_value = [
|
||||
b"slot:opc_tags:1", b"slot:opc_tags:2", b"slot:opc_tags:3"]
|
||||
|
||||
slot_manager.redis_client.mget.return_value = [
|
||||
b"value1", "value2", None]
|
||||
slot_manager.get = MagicMock(
|
||||
side_effect=[
|
||||
"value1",
|
||||
"value2",
|
||||
None
|
||||
]
|
||||
)
|
||||
|
||||
response = await slot_manager.load_opc_slots()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from unittest.mock import MagicMock, patch, AsyncMock, call
|
||||
from unittest.mock import MagicMock, patch, AsyncMock, call, ANY
|
||||
from datetime import timedelta
|
||||
import base64
|
||||
import json
|
||||
@@ -25,7 +25,7 @@ async def test_load_schedule(_mock_message_to_dict, temporal_manager):
|
||||
yield MagicMock(
|
||||
id="test-schedule-id",
|
||||
search_attributes={
|
||||
"Orchestrated": ["true"]
|
||||
"orchestrated": ["true"]
|
||||
}
|
||||
)
|
||||
yield MagicMock(
|
||||
@@ -136,16 +136,18 @@ async def test_create_schedule(
|
||||
|
||||
mock_schedule_action_start_workflow.assert_has_calls([
|
||||
call(
|
||||
workflow="test-workflow",
|
||||
args=input_data['schedules']['test-schedule'],
|
||||
"test-workflow",
|
||||
input_data['schedules']['test-schedule'],
|
||||
id="test-schedule",
|
||||
task_queue="test-workflow-queue"
|
||||
task_queue="test-workflow-queue",
|
||||
execution_timeout=ANY
|
||||
),
|
||||
call(
|
||||
workflow="test-workflow",
|
||||
args=input_data['schedules']['test-schedule-invalid-frequency'],
|
||||
"test-workflow",
|
||||
input_data['schedules']['test-schedule-invalid-frequency'],
|
||||
id="test-schedule-invalid-frequency",
|
||||
task_queue="test-workflow-queue"
|
||||
task_queue="test-workflow-queue",
|
||||
execution_timeout=ANY
|
||||
)
|
||||
])
|
||||
|
||||
|
||||
@@ -12,9 +12,12 @@ from orchestrator.utils.orchestrator_functions import (
|
||||
|
||||
def test_common_config():
|
||||
config = {
|
||||
"workflow_type": "scouter",
|
||||
"schedule_name": "test_schedule",
|
||||
"model_id": "test_model_id",
|
||||
"model_name": "test_model_name"
|
||||
"models": {
|
||||
"name": "test_model_name"
|
||||
}
|
||||
}
|
||||
result = common_config(config)
|
||||
expected = {
|
||||
@@ -30,9 +33,12 @@ def test_common_config():
|
||||
|
||||
def test_scouter():
|
||||
config = {
|
||||
"workflow_type": "scouter",
|
||||
"schedule_name": "test_schedule",
|
||||
"model_id": "test_model_id",
|
||||
"model_name": "test_model_name",
|
||||
"models": {
|
||||
"name": "test_model_name"
|
||||
},
|
||||
"filters": [
|
||||
{
|
||||
"filter_name": "test_filter_name",
|
||||
@@ -127,7 +133,9 @@ def test_predictions_batch(mock_process_path_priority,
|
||||
"schedule_name": "test_schedule",
|
||||
"workflow_type": "predictions_batch",
|
||||
"model_id": "test_model_id",
|
||||
"model_name": "test_model_name",
|
||||
"models": {
|
||||
"name": "test_model_name"
|
||||
},
|
||||
"query": "test_query",
|
||||
"write_tags": [
|
||||
{
|
||||
@@ -244,6 +252,7 @@ def test_gather_read_tags():
|
||||
"schedule_name": "test_schedule",
|
||||
"read_tags": [
|
||||
{
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address"
|
||||
}
|
||||
@@ -253,10 +262,12 @@ def test_gather_read_tags():
|
||||
"schedule_name": "test_schedule2",
|
||||
"read_tags": [
|
||||
{
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2"
|
||||
},
|
||||
{
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address3"
|
||||
}
|
||||
@@ -267,17 +278,20 @@ def test_gather_read_tags():
|
||||
result = gather_read_tags(pipelines)
|
||||
|
||||
expected = {
|
||||
"test_server_name:test_tag_address": {
|
||||
"1:test_tag_address": {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address",
|
||||
"topics": ["raw_test_schedule"]
|
||||
},
|
||||
"test_server_name2:test_tag_address2": {
|
||||
"2:test_tag_address2": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address2",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
},
|
||||
"test_server_name2:test_tag_address3": {
|
||||
"2:test_tag_address3": {
|
||||
"server_id": "2",
|
||||
"server_name": "test_server_name2",
|
||||
"tag_address": "test_tag_address3",
|
||||
"topics": ["raw_test_schedule2"]
|
||||
@@ -289,11 +303,13 @@ def test_gather_read_tags():
|
||||
|
||||
def test_build_tag_config():
|
||||
tag = {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address"
|
||||
}
|
||||
opc_servers = {
|
||||
"test_server_name": {
|
||||
"1": {
|
||||
"server_name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"uri": "test_uri",
|
||||
"security_spec": {
|
||||
@@ -309,11 +325,13 @@ def test_build_tag_config():
|
||||
expected = {
|
||||
"1": {
|
||||
"test_server_name": {
|
||||
"server_id": "1",
|
||||
"name": "test_server_name",
|
||||
"url": "test_url",
|
||||
"server_uri": "test_uri",
|
||||
"tags": {
|
||||
"test_tag_address": {
|
||||
"server_id": "1",
|
||||
"server_name": "test_server_name",
|
||||
"tag_address": "test_tag_address"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user