@@ -84,20 +84,29 @@ def start_workflow(md, da, workflow_file_name, variables) -> str:
84
84
return r_wfid
85
85
86
86
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 :
88
95
"""A convenience function to wait for and check a workflow execution
89
96
(by inspecting the anticipated DB/API records). The workflow is expected
90
97
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.
92
100
"""
101
+ assert isinstance (da , UnitTestAPIAdapter )
102
+ assert isinstance (r_wfid , str )
93
103
94
104
# We wait for the workflow to complete by polling the API and checking
95
105
# the running workflow's 'done' status. The user can specify whether
96
106
# the workflow is expected to succeed or fail. Any further checks
97
107
# are the responsibility of the caller.
98
108
attempts = 0
99
109
done = False
100
- r_wf = None
101
110
while not done :
102
111
response = da .get_running_workflow (running_workflow_id = r_wfid )
103
112
assert "running_workflow" in response
@@ -106,10 +115,11 @@ def wait_for_workflow(da, r_wfid, expect_success=True):
106
115
done = True
107
116
else :
108
117
attempts += 1
109
- if attempts > 10 :
118
+ if attempts > completion_attempts :
110
119
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.
113
123
assert r_wf ["done" ]
114
124
assert r_wf ["success" ] == expect_success
115
125
0 commit comments