@@ -2,6 +2,7 @@ import * as fs from 'fs';
22import * as path from 'path' ;
33import { WorkflowDef } from "../../../common" ;
44import { MetadataClient } from "../../metadataClient" ;
5+ import { WorkflowExecutor } from "../../executor" ;
56
67export class TestUtil {
78 private static metadataClient : MetadataClient ;
@@ -35,6 +36,39 @@ export class TestUtil {
3536 }
3637 }
3738
39+ // Helper function to wait for workflow completion
40+ public static async waitForWorkflowCompletion (
41+ executor : WorkflowExecutor ,
42+ workflowId : string ,
43+ maxWaitMs : number = 300000 , // 5 minutes default
44+ pollIntervalMs : number = 100 // 100ms default
45+ ) {
46+ const startTime = Date . now ( ) ;
47+
48+ while ( Date . now ( ) - startTime < maxWaitMs ) {
49+ try {
50+ const workflowStatus = await executor . getWorkflow ( workflowId , true ) ;
51+
52+ // Check if workflow is in a terminal state
53+ if ( [ 'COMPLETED' , 'FAILED' , 'TERMINATED' , 'TIMED_OUT' ] . includes ( workflowStatus . status ! ) ) {
54+ console . debug ( `Workflow ${ workflowId } reached terminal state: ${ workflowStatus . status } ` ) ;
55+ return workflowStatus ;
56+ }
57+
58+ console . debug ( `Workflow ${ workflowId } status: ${ workflowStatus . status } , waiting...` ) ;
59+
60+ // Wait before next poll
61+ await new Promise ( resolve => setTimeout ( resolve , pollIntervalMs ) ) ;
62+
63+ } catch ( error ) {
64+ console . warn ( `Error checking workflow status for ${ workflowId } :` , error ) ;
65+ await new Promise ( resolve => setTimeout ( resolve , pollIntervalMs ) ) ;
66+ }
67+ }
68+
69+ throw new Error ( `Workflow ${ workflowId } did not complete within ${ maxWaitMs } ms` ) ;
70+ }
71+
3872 /**
3973 * Unregister a workflow
4074 */
0 commit comments