|
12 | 12 | from conductor.client.workflow.executor.workflow_executor import WorkflowExecutor |
13 | 13 | from conductor.client.workflow.task.simple_task import SimpleTask |
14 | 14 | from tests.integration.resources.worker.python.python_worker import * |
15 | | -from tests.integration.retry_helpers import retry_scenario, TERMINAL_WORKFLOW_STATES |
| 15 | +from tests.integration.retry_helpers import retry_scenario, wait_for_workflow_terminal |
16 | 16 |
|
17 | 17 | WORKFLOW_NAME = "sdk_python_integration_test_workflow" |
18 | 18 | WORKFLOW_DESCRIPTION = "Python SDK Integration Test" |
@@ -207,34 +207,19 @@ def scenario_workflow_execution( |
207 | 207 |
|
208 | 208 | def _wait_for_workflow_terminal(workflow_id, workflow_executor, deadline, |
209 | 209 | poll_interval=2): |
210 | | - """Poll until the workflow reaches a terminal state or the shared deadline |
211 | | - passes, logging progress (wf id + elapsed) so a slow-but-eventually-complete |
212 | | - run is visible instead of surfacing as a bare timeout. A transient poll error |
213 | | - is logged and retried. Returns the last observed status; the caller still |
214 | | - runs validate_workflow_status for the actual assertion. |
| 210 | + """Poll until the workflow reaches a terminal state or the shared ``deadline`` |
| 211 | + (a ``time.time()`` wall-clock value shared across a batch) passes, logging |
| 212 | + progress so a slow-but-eventually-complete run is visible instead of a bare |
| 213 | + timeout. A transient poll error is logged and retried. Returns the last |
| 214 | + observed status; the caller still runs validate_workflow_status for the |
| 215 | + actual assertion. Thin wrapper over the shared ``wait_for_workflow_terminal``. |
215 | 216 | """ |
216 | | - start = time.time() |
217 | | - status = None |
218 | | - while True: |
219 | | - try: |
220 | | - workflow = workflow_executor.get_workflow( |
221 | | - workflow_id=workflow_id, include_tasks=False) |
222 | | - status = workflow.status |
223 | | - except Exception as e: # transient blip against the shared server |
224 | | - logger.warning('error polling workflow %s (%.0fs elapsed): %s', |
225 | | - workflow_id, time.time() - start, e) |
226 | | - if status in TERMINAL_WORKFLOW_STATES: |
227 | | - logger.info('workflow %s reached %s after %.0fs', |
228 | | - workflow_id, status, time.time() - start) |
229 | | - return status |
230 | | - if time.time() >= deadline: |
231 | | - logger.warning( |
232 | | - 'workflow %s still %s after %.0fs; giving up wait', |
233 | | - workflow_id, status, time.time() - start) |
234 | | - return status |
235 | | - logger.info('workflow %s still %s after %.0fs; waiting', |
236 | | - workflow_id, status, time.time() - start) |
237 | | - sleep(poll_interval) |
| 217 | + workflow = wait_for_workflow_terminal( |
| 218 | + workflow_executor, workflow_id, |
| 219 | + timeout_seconds=max(0.0, deadline - time.time()), |
| 220 | + poll_interval=poll_interval, include_tasks=False, |
| 221 | + swallow='all', log=logger.info) |
| 222 | + return getattr(workflow, 'status', None) |
238 | 223 |
|
239 | 224 |
|
240 | 225 | def generate_workflow(workflow_executor: WorkflowExecutor, workflow_name: str = WORKFLOW_NAME, |
@@ -467,22 +452,13 @@ def scenario_execute_workflow_error_handling(workflow_executor: WorkflowExecutor |
467 | 452 |
|
468 | 453 |
|
469 | 454 | def _wait_for_workflow_completion(workflow_executor: WorkflowExecutor, workflow_id: str, max_wait_seconds: int = 60): |
470 | | - """Helper function to wait for workflow completion""" |
471 | | - import time |
472 | | - start_time = time.time() |
473 | | - |
474 | | - while time.time() - start_time < max_wait_seconds: |
475 | | - workflow = workflow_executor.get_workflow(workflow_id, True) |
476 | | - |
477 | | - if workflow.status in TERMINAL_WORKFLOW_STATES: |
478 | | - logger.debug(f'Workflow {workflow_id} finished with status: {workflow.status}') |
479 | | - return workflow |
480 | | - |
481 | | - logger.debug(f'Waiting for workflow {workflow_id}... Status: {workflow.status}') |
482 | | - time.sleep(2) |
483 | | - |
484 | | - # Return final state even if not completed |
485 | | - return workflow_executor.get_workflow(workflow_id, True) |
| 455 | + """Helper function to wait for workflow completion. Thin wrapper over the |
| 456 | + shared ``wait_for_workflow_terminal``; returns the last observed Workflow. |
| 457 | + """ |
| 458 | + return wait_for_workflow_terminal( |
| 459 | + workflow_executor, workflow_id, |
| 460 | + timeout_seconds=max_wait_seconds, poll_interval=2, |
| 461 | + include_tasks=True, swallow='none', log=logger.debug) |
486 | 462 |
|
487 | 463 | # ===== SIGNAL TESTS ===== |
488 | 464 |
|
|
0 commit comments