Skip to content

Commit 294c765

Browse files
committed
Merge branch '2.0' into fanout-jobs
2 parents cc5d8cc + 37d5ad2 commit 294c765

File tree

3 files changed

+103
-4
lines changed

3 files changed

+103
-4
lines changed

tests/test_test_api_adapter.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,20 @@ def test_get_running_workflow_step_with_prior_step():
324324
def test_create_instance():
325325
# Arrange
326326
utaa = UnitTestWorkflowAPIAdapter()
327+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
328+
response = utaa.create_running_workflow(
329+
user_id="dlister",
330+
workflow_id=response["id"],
331+
project_id=TEST_PROJECT_ID,
332+
variables={},
333+
)
334+
response, _ = utaa.create_running_workflow_step(
335+
running_workflow_id=response["id"], step="step-1"
336+
)
337+
rwfs_id = response["id"]
327338

328339
# Act
329-
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
340+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
330341

331342
# Assert
332343
assert "id" in response
@@ -335,14 +346,79 @@ def test_create_instance():
335346
def test_create_and_get_instance():
336347
# Arrange
337348
utaa = UnitTestWorkflowAPIAdapter()
338-
response = utaa.create_instance(running_workflow_step_id="r-workflow-step-000")
349+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
350+
response = utaa.create_running_workflow(
351+
user_id="dlister",
352+
workflow_id=response["id"],
353+
project_id=TEST_PROJECT_ID,
354+
variables={},
355+
)
356+
response, _ = utaa.create_running_workflow_step(
357+
running_workflow_id=response["id"], step="step-1"
358+
)
359+
rwfs_id = response["id"]
360+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
339361
instance_id = response["id"]
340362

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

344366
# Assert
345-
assert response["running_workflow_step_id"] == "r-workflow-step-000"
367+
assert response["running_workflow_step_id"] == rwfs_id
368+
369+
370+
def test_create_instance_and_get_step_instance_directory():
371+
# Arrange
372+
utaa = UnitTestWorkflowAPIAdapter()
373+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
374+
response = utaa.create_running_workflow(
375+
user_id="dlister",
376+
workflow_id=response["id"],
377+
project_id=TEST_PROJECT_ID,
378+
variables={},
379+
)
380+
response, _ = utaa.create_running_workflow_step(
381+
running_workflow_id=response["id"], step="step-1"
382+
)
383+
rwfs_id = response["id"]
384+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
385+
i_id = response["id"]
386+
387+
# Act
388+
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfs_id)
389+
390+
# Assert
391+
assert "instance_directory" in response
392+
assert response["instance_directory"] == f".{i_id}"
393+
394+
395+
def test_create_instance_and_get_step_instance_directory_by_name():
396+
# Arrange
397+
utaa = UnitTestWorkflowAPIAdapter()
398+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
399+
wf_id = response["id"]
400+
response = utaa.create_running_workflow(
401+
user_id="dlister",
402+
workflow_id=wf_id,
403+
project_id=TEST_PROJECT_ID,
404+
variables={},
405+
)
406+
rwf_id = response["id"]
407+
response, _ = utaa.create_running_workflow_step(
408+
running_workflow_id=rwf_id, step="step-1"
409+
)
410+
rwfs_id = response["id"]
411+
response = utaa.create_instance(running_workflow_step_id=rwfs_id)
412+
i_id = response["id"]
413+
414+
# Act
415+
response, _ = utaa.get_running_workflow_step_by_name(
416+
running_workflow_id=rwf_id, name="step-1"
417+
)
418+
419+
# Assert
420+
assert "instance_directory" in response
421+
assert response["instance_directory"] == f".{i_id}"
346422

347423

348424
def test_get_workflow_steps_driving_this_step_when_1st_step():

tests/wapi_adapter.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_workflow_steps_driving_this_step(
288288
"steps": wf_response["steps"].copy(),
289289
}, 0
290290

291-
def get_instance(self, *, instance_id: str) -> dict[str, Any]:
291+
def get_instance(self, *, instance_id: str) -> tuple[dict[str, Any], int]:
292292
UnitTestWorkflowAPIAdapter.lock.acquire()
293293
with open(_INSTANCE_PICKLE_FILE, "rb") as pickle_file:
294294
instances = Unpickler(pickle_file).load()
@@ -378,6 +378,17 @@ def create_instance(self, *, running_workflow_step_id: str) -> dict[str, Any]:
378378

379379
with open(_INSTANCE_PICKLE_FILE, "wb") as pickle_file:
380380
Pickler(pickle_file).dump(instances)
381+
382+
# Use the instance ID as the step's instance-directory (prefixing with '.')
383+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "rb") as pickle_file:
384+
running_workflow_step = Unpickler(pickle_file).load()
385+
assert running_workflow_step_id in running_workflow_step
386+
running_workflow_step[running_workflow_step_id][
387+
"instance_directory"
388+
] = f".{instance_id}"
389+
with open(_RUNNING_WORKFLOW_STEP_PICKLE_FILE, "wb") as pickle_file:
390+
Pickler(pickle_file).dump(running_workflow_step)
391+
381392
UnitTestWorkflowAPIAdapter.lock.release()
382393

383394
return {"id": instance_id}

workflow/workflow_abc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ def get_running_workflow_step(
240240
# }
241241
# If not present an empty dictionary should be returned.
242242
#
243+
# Additionally, if the step has started (an instance has been created)
244+
# the response will contain a "instance_directory" top-level property
245+
# that is the directory within the Project that's the step's working directory.
246+
#
247+
# "instance_directory": ".instance-00000000-0000-0000-0000-00000000000a",
248+
#
243249
# For steps that are not the first in a workflow the following field
244250
# can be expected in the response: -
245251
#
@@ -273,6 +279,12 @@ def get_running_workflow_step_by_name(
273279
# }
274280
# If not present an empty dictionary should be returned.
275281
#
282+
# Additionally, if the step has started (an instance has been created)
283+
# the response will contain a "instance_directory" top-level property
284+
# that is the directory within the Project that's the step's working directory.
285+
#
286+
# "instance_directory": ".instance-00000000-0000-0000-0000-00000000000a",
287+
#
276288
# For steps that are not the first in a workflow the following field
277289
# can be expected in the response: -
278290
#

0 commit comments

Comments
 (0)