@@ -891,6 +891,57 @@ await instance.WaitForCompletion(
891891 expectedOutput : "Bye!" ) ;
892892
893893 LogAssert . NoWarningsOrErrors ( this . testService . LogProvider ) ;
894+ }
895+
896+ [ Fact ]
897+ public async Task TerminateSuspendedOrchestration ( )
898+ {
899+ string input = $ "Hello { DateTime . UtcNow : o} ";
900+ string orchestrationName = "OrchestrationWithTimer" ;
901+ TimeSpan delay = TimeSpan . FromSeconds ( 30 ) ;
902+
903+ // Performs a delay and then returns the input
904+ TestInstance < string > instance = await this . testService . RunOrchestration (
905+ input ,
906+ orchestrationName ,
907+ implementation : ( ctx , input ) => ctx . CreateTimer ( ctx . CurrentUtcDateTime . Add ( delay ) , input ) ) ;
908+
909+ // Wait for the orchestration to finish starting
910+ await instance . WaitForStart ( ) ;
911+
912+ // Suspend the orchestration so that it won't process any new events
913+ await instance . SuspendAsync ( ) ;
914+
915+ // Wait for the orchestration to become suspended
916+ OrchestrationState state = await instance . GetStateAsync ( ) ;
917+ TimeSpan waitForSuspendTimeout = TimeSpan . FromSeconds ( 5 ) ;
918+ using CancellationTokenSource cts = new ( waitForSuspendTimeout ) ;
919+ while ( ! cts . IsCancellationRequested && state . OrchestrationStatus != OrchestrationStatus . Suspended )
920+ {
921+ state = await instance . GetStateAsync ( ) ;
922+ }
923+ Assert . Equal ( OrchestrationStatus . Suspended , state . OrchestrationStatus ) ;
924+
925+ // Now terminate the orchestration
926+ await instance . TerminateAsync ( "Bye!" ) ;
927+
928+ TimeSpan waitForTerminationTimeout = TimeSpan . FromSeconds ( 5 ) ;
929+ state = await instance . WaitForCompletion (
930+ waitForTerminationTimeout ,
931+ expectedStatus : OrchestrationStatus . Terminated ,
932+ expectedOutput : "Bye!" ) ;
933+
934+ // Validate logs
935+ LogAssert . NoWarningsOrErrors ( this . testService . LogProvider ) ;
936+ LogAssert . Sequence (
937+ this . testService . LogProvider ,
938+ LogAssert . AcquiredAppLock ( ) ,
939+ LogAssert . CheckpointStarting ( orchestrationName ) ,
940+ LogAssert . CheckpointCompleted ( orchestrationName ) ,
941+ LogAssert . CheckpointStarting ( orchestrationName ) ,
942+ LogAssert . CheckpointCompleted ( orchestrationName ) ,
943+ LogAssert . CheckpointStarting ( orchestrationName ) ,
944+ LogAssert . CheckpointCompleted ( orchestrationName ) ) ;
894945 }
895946 }
896947}
0 commit comments