@@ -1128,6 +1128,57 @@ describe("Orchestration Executor", () => {
11281128 expect ( completeAction ?. getOrchestrationstatus ( ) ) . toEqual ( pb . OrchestrationStatus . ORCHESTRATION_STATUS_FAILED ) ;
11291129 } ) ;
11301130 } ) ;
1131+
1132+ it ( "should complete immediately when whenAll is called with an empty task array" , async ( ) => {
1133+ const orchestrator : TOrchestrator = async function * ( _ctx : OrchestrationContext ) : any {
1134+ const results = yield whenAll ( [ ] ) ;
1135+ return results ;
1136+ } ;
1137+
1138+ const registry = new Registry ( ) ;
1139+ const orchestratorName = registry . addOrchestrator ( orchestrator ) ;
1140+
1141+ const oldEvents : any [ ] = [ ] ;
1142+ const newEvents = [ newOrchestratorStartedEvent ( ) , newExecutionStartedEvent ( orchestratorName , TEST_INSTANCE_ID ) ] ;
1143+
1144+ const executor = new OrchestrationExecutor ( registry , testLogger ) ;
1145+ const result = await executor . execute ( TEST_INSTANCE_ID , oldEvents , newEvents ) ;
1146+
1147+ // The orchestration should complete immediately with an empty array result
1148+ const completeAction = getAndValidateSingleCompleteOrchestrationAction ( result ) ;
1149+ expect ( completeAction ?. getOrchestrationstatus ( ) ) . toEqual ( pb . OrchestrationStatus . ORCHESTRATION_STATUS_COMPLETED ) ;
1150+ expect ( completeAction ?. getResult ( ) ?. getValue ( ) ) . toEqual ( JSON . stringify ( [ ] ) ) ;
1151+ } ) ;
1152+
1153+ it ( "should complete when whenAll with empty array is followed by more work" , async ( ) => {
1154+ const hello = ( _ : any , name : string ) => `Hello ${ name } !` ;
1155+
1156+ const orchestrator : TOrchestrator = async function * ( ctx : OrchestrationContext ) : any {
1157+ const emptyResults = yield whenAll ( [ ] ) ;
1158+ const activityResult = yield ctx . callActivity ( hello , "World" ) ;
1159+ return { emptyResults, activityResult } ;
1160+ } ;
1161+
1162+ const registry = new Registry ( ) ;
1163+ const orchestratorName = registry . addOrchestrator ( orchestrator ) ;
1164+ const activityName = registry . addActivity ( hello ) ;
1165+
1166+ // First execution: should schedule the activity after completing whenAll([])
1167+ const oldEvents : any [ ] = [ ] ;
1168+ const newEvents = [ newOrchestratorStartedEvent ( ) , newExecutionStartedEvent ( orchestratorName , TEST_INSTANCE_ID ) ] ;
1169+
1170+ const executor = new OrchestrationExecutor ( registry , testLogger ) ;
1171+ const result = await executor . execute ( TEST_INSTANCE_ID , oldEvents , newEvents ) ;
1172+
1173+ // The whenAll([]) should complete, then an activity should be scheduled
1174+ expect ( result . actions . length ) . toEqual ( 1 ) ;
1175+ expect ( result . actions [ 0 ] . hasScheduletask ( ) ) . toBeTruthy ( ) ;
1176+ expect ( result . actions [ 0 ] . getScheduletask ( ) ?. getName ( ) ) . toEqual ( activityName ) ;
1177+ } ) ;
1178+
1179+ it ( "should throw when whenAny is called with an empty task array" , ( ) => {
1180+ expect ( ( ) => whenAny ( [ ] ) ) . toThrow ( "whenAny requires at least one task" ) ;
1181+ } ) ;
11311182} ) ;
11321183
11331184function getAndValidateSingleCompleteOrchestrationAction (
0 commit comments