Skip to content

Commit

Permalink
wait until workflow complete in rest endpoint unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Jan 13, 2025
1 parent ada7446 commit 562a897
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 7 additions & 7 deletions biosim_server/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def root() -> dict[str, str]:


@app.post(
"/verify",
"/verify_omex",
response_model=OmexVerifyWorkflowOutput,
name="Uniform Time Course Comparison from OMEX/COMBINE archive",
operation_id="verify",
operation_id="start-verify-omex",
tags=["Verification"],
dependencies=[Depends(get_temporal_client), Depends(get_file_service)],
summary="Compare UTC outputs from a deterministic SBML model within an OMEX/COMBINE archive.")
async def verify(
async def start_verify_omex(
uploaded_file: UploadFile = File(..., description="OMEX/COMBINE archive containing a deterministic SBML model"),
workflow_id_prefix: str = Query(default="verification-", description="Prefix for the workflow id."),
simulators: list[str] = Query(default=["amici", "copasi", "pysces", "tellurium", "vcell"],
Expand Down Expand Up @@ -190,14 +190,14 @@ async def verify(


@app.get(
"/get-output/{workflow_id}",
"/verify_omex/{workflow_id}",
response_model=OmexVerifyWorkflowOutput,
operation_id='get-output',
operation_id='get-verify-omex',
tags=["Results"],
dependencies=[Depends(get_biosim_service), Depends(get_file_service)],
summary='Get the results of an existing verification run.')
async def get_output(workflow_id: str) -> OmexVerifyWorkflowOutput:
logger.info(f"in get /get-output/{workflow_id}")
async def get_verify_omex(workflow_id: str) -> OmexVerifyWorkflowOutput:
logger.info(f"in get /verify_omex/{workflow_id}")

try:
# query temporal for the workflow output
Expand Down
2 changes: 1 addition & 1 deletion biosim_server/verify/workflows/omex_verify_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ async def run(self, verify_input: OmexVerifyWorkflowInput) -> OmexVerifyWorkflow
)
workflow.logger.info(f"Report generated at: {report_location}")

# Return the report location
self.verify_output.workflow_status = OmexVerifyWorkflowStatus.COMPLETED
return self.verify_output
14 changes: 12 additions & 2 deletions tests/api/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
import logging
import os
from copy import copy
from pathlib import Path
Expand Down Expand Up @@ -30,7 +32,7 @@ async def test_get_output_not_found(verify_workflow_input: OmexVerifyWorkflowInp

async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as test_client:
# test with non-existent verification_id
response = await test_client.get(f"/get-output/non-existent-id")
response = await test_client.get(f"/verify_omex/non-existent-id")
assert response.status_code == 404


Expand Down Expand Up @@ -59,7 +61,7 @@ async def test_verify_and_get_output(verify_workflow_input: OmexVerifyWorkflowIn
with open(file_path, "rb") as file:
files = {"uploaded_file": (
"BIOMD0000000010_tellurium_Negative_feedback_and_ultrasen.omex", file, "application/zip")}
response = await test_client.post("/verify", files=files, params=query_params)
response = await test_client.post("/verify_omex", files=files, params=query_params)
assert response.status_code == 200

workflow_output = OmexVerifyWorkflowOutput.model_validate(response.json())
Expand All @@ -80,6 +82,13 @@ async def test_verify_and_get_output(verify_workflow_input: OmexVerifyWorkflowIn
workflow_run_id=workflow_output.workflow_run_id
)

while output.workflow_status != OmexVerifyWorkflowStatus.COMPLETED:
await asyncio.sleep(5)
response = await test_client.get(f"/verify_omex/{output.workflow_input.workflow_id}")
if response.status_code == 200:
output = OmexVerifyWorkflowOutput.model_validate(response.json())
logging.info(f"polling, job status is: {output.workflow_status}")

# set timestamp, job_id, and omex_s3_path before comparison (these are set on server)
expected_verify_workflow_output = OmexVerifyWorkflowOutput(
workflow_input=copy(verify_workflow_input),
Expand All @@ -91,6 +100,7 @@ async def test_verify_and_get_output(verify_workflow_input: OmexVerifyWorkflowIn
expected_verify_workflow_output.workflow_input.workflow_id = output.workflow_input.workflow_id
expected_verify_workflow_output.timestamp = output.timestamp
expected_verify_workflow_output.workflow_run_id = output.workflow_run_id
expected_verify_workflow_output.workflow_status = OmexVerifyWorkflowStatus.COMPLETED
assert expected_verify_workflow_output == output

# verify the omex_s3_path file to the original file_path
Expand Down

0 comments on commit 562a897

Please sign in to comment.