Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 79 additions & 3 deletions tests/test_test_api_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,20 @@ def test_get_running_workflow_step_with_prior_step():
def test_create_instance():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(workflow_definition={"name": "blah"})
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=response["id"],
project_id=TEST_PROJECT_ID,
variables={},
)
response, _ = utaa.create_running_workflow_step(
running_workflow_id=response["id"], step="step-1"
)
rwfs_id = response["id"]

# Act
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
response = utaa.create_instance(running_workflow_step_id=rwfs_id)

# Assert
assert "id" in response
Expand All @@ -335,14 +346,79 @@ def test_create_instance():
def test_create_and_get_instance():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
response = utaa.create_workflow(workflow_definition={"name": "blah"})
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=response["id"],
project_id=TEST_PROJECT_ID,
variables={},
)
response, _ = utaa.create_running_workflow_step(
running_workflow_id=response["id"], step="step-1"
)
rwfs_id = response["id"]
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
instance_id = response["id"]

# Act
response, _ = utaa.get_instance(instance_id=instance_id)

# Assert
assert response["running_workflow_step_id"] == "r-workflow-step-000"
assert response["running_workflow_step_id"] == rwfs_id


def test_create_instance_and_get_step_instance_directory():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(workflow_definition={"name": "blah"})
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=response["id"],
project_id=TEST_PROJECT_ID,
variables={},
)
response, _ = utaa.create_running_workflow_step(
running_workflow_id=response["id"], step="step-1"
)
rwfs_id = response["id"]
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
i_id = response["id"]

# Act
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfs_id)

# Assert
assert "instance_directory" in response
assert response["instance_directory"] == f".{i_id}"


def test_create_instance_and_get_step_instance_directory_by_name():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(workflow_definition={"name": "blah"})
wf_id = response["id"]
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=wf_id,
project_id=TEST_PROJECT_ID,
variables={},
)
rwf_id = response["id"]
response, _ = utaa.create_running_workflow_step(
running_workflow_id=rwf_id, step="step-1"
)
rwfs_id = response["id"]
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
i_id = response["id"]

# Act
response, _ = utaa.get_running_workflow_step_by_name(
running_workflow_id=rwf_id, name="step-1"
)

# Assert
assert "instance_directory" in response
assert response["instance_directory"] == f".{i_id}"


def test_get_workflow_steps_driving_this_step_when_1st_step():
Expand Down
13 changes: 12 additions & 1 deletion tests/wapi_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def get_workflow_steps_driving_this_step(
"steps": wf_response["steps"].copy(),
}, 0

def get_instance(self, *, instance_id: str) -> dict[str, Any]:
def get_instance(self, *, instance_id: str) -> tuple[dict[str, Any], int]:
UnitTestWorkflowAPIAdapter.lock.acquire()
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
instances = Unpickler(pickle_file).load()
Expand Down Expand Up @@ -377,6 +377,17 @@ def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:

with open(_INSTANCE_PICKLE_FILE, "wb") as pickle_file:
Pickler(pickle_file).dump(instances)

# Use the instance ID as the step's instance-directory (prefixing with '.')
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
running_workflow_step = Unpickler(pickle_file).load()
assert running_workflow_step_id in running_workflow_step
running_workflow_step[running_workflow_step_id][
"instance_directory"
] = f".{instance_id}"
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
Pickler(pickle_file).dump(running_workflow_step)

UnitTestWorkflowAPIAdapter.lock.release()

return {"id": instance_id}
Expand Down
6 changes: 0 additions & 6 deletions workflow/workflow_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ def get_workflow_steps_driving_this_step(
# }
# ]
# }
#
# Additionally, if the step has started (an instance has been created)
# each entry on the array of steps will contain a "instance_directory" property
# that is the directory within the Project that's the step's working directory.
#
# "instance_directory": ".instance-00000000-0000-0000-0000-00000000000a",

@abstractmethod
def get_instance(self, *, instance_id: str) -> tuple[dict[str, Any], int]:
Expand Down