Skip to content

Commit

Permalink
🐛Director-v2: Fix UNKNOWN state not correctly converted (#4660)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg authored Aug 25, 2023
1 parent 833e1c2 commit 7b0f9a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
StateType.WAITING_FOR_RESOURCES: RunningState.WAITING_FOR_RESOURCES,
}

RUNNING_STATE_TO_DB = {
**{v: k for k, v in DB_TO_RUNNING_STATE.items()},
RUNNING_STATE_TO_DB = {v: k for k, v in DB_TO_RUNNING_STATE.items()} | {
RunningState.UNKNOWN: StateType.FAILED
}


Expand Down
2 changes: 1 addition & 1 deletion services/director-v2/tests/unit/test_models_comp_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_computation_task_model_export_to_db_model(
db_model = model_instance.to_db_model()

assert isinstance(db_model, dict)
StateType(db_model["state"])
assert StateType(db_model["state"])


@pytest.mark.parametrize(
Expand Down
24 changes: 20 additions & 4 deletions services/director-v2/tests/unit/test_utils_db.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from contextlib import suppress
from typing import Any, Dict, Type, cast
from typing import Any, cast

import pytest
from models_library.clusters import BaseCluster, Cluster
from models_library.projects_state import RunningState
from pydantic import BaseModel
from simcore_service_director_v2.utils.db import to_clusters_db
from simcore_postgres_database.models.comp_pipeline import StateType
from simcore_service_director_v2.utils.db import (
DB_TO_RUNNING_STATE,
RUNNING_STATE_TO_DB,
to_clusters_db,
)


@pytest.mark.parametrize(
"model_cls",
(Cluster,),
[Cluster],
)
def test_export_clusters_to_db(
model_cls: Type[BaseModel], model_cls_examples: Dict[str, Dict[str, Any]]
model_cls: type[BaseModel], model_cls_examples: dict[str, dict[str, Any]]
):
for example in model_cls_examples.values():
owner_gid = example["owner"]
Expand All @@ -29,3 +35,13 @@ def test_export_clusters_to_db(
assert list(cluster_db_dict.keys()) == [
x for x in example if x not in keys_not_in_db
]


@pytest.mark.parametrize("input_running_state", RunningState)
def test_running_state_to_db(input_running_state: RunningState):
assert input_running_state in RUNNING_STATE_TO_DB


@pytest.mark.parametrize("input_state_type", StateType)
def test_db_to_running_state(input_state_type: StateType):
assert input_state_type in DB_TO_RUNNING_STATE

0 comments on commit 7b0f9a9

Please sign in to comment.