Skip to content

Commit 6cbd96f

Browse files
author
Alan Christie
committed
test: Better workflow engine testing
1 parent 0275739 commit 6cbd96f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tests/test_workflow_engine_examples.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,29 @@ def start_workflow(md, da, workflow_file_name, variables) -> str:
8484
return r_wfid
8585

8686

87-
def wait_for_workflow(da, r_wfid, expect_success=True):
87+
def wait_for_workflow(
88+
da,
89+
r_wfid,
90+
*,
91+
expect_success=True,
92+
completion_attempts=20,
93+
completion_poll_period_s=0.25,
94+
) -> None:
8895
"""A convenience function to wait for and check a workflow execution
8996
(by inspecting the anticipated DB/API records). The workflow is expected
9097
to start (because start_workflow() has been called), this function
91-
waits for the running workflow to complete (by polling the API).
98+
waits for the running workflow to complete (by polling the API)
99+
while also checking the expected success/failure status.
92100
"""
101+
assert isinstance(da, UnitTestAPIAdapter)
102+
assert isinstance(r_wfid, str)
93103

94104
# We wait for the workflow to complete by polling the API and checking
95105
# the running workflow's 'done' status. The user can specify whether
96106
# the workflow is expected to succeed or fail. Any further checks
97107
# are the responsibility of the caller.
98108
attempts = 0
99109
done = False
100-
r_wf = None
101110
while not done:
102111
response = da.get_running_workflow(running_workflow_id=r_wfid)
103112
assert "running_workflow" in response
@@ -106,10 +115,11 @@ def wait_for_workflow(da, r_wfid, expect_success=True):
106115
done = True
107116
else:
108117
attempts += 1
109-
if attempts > 10:
118+
if attempts > completion_attempts:
110119
break
111-
time.sleep(0.5)
112-
assert r_wf
120+
time.sleep(completion_poll_period_s)
121+
# When we get here the workflow must have finished (not timed-out),
122+
# and it must have passed (or failed) according the the caller's expectation.
113123
assert r_wf["done"]
114124
assert r_wf["success"] == expect_success
115125

0 commit comments

Comments
 (0)