@@ -42,6 +42,17 @@ public TimeSpan Duration
4242 }
4343 }
4444
45+ /// <summary>
46+ /// The minimum number of times each child component should run. Default set to 0.
47+ /// </summary>
48+ public int MinimumIteration
49+ {
50+ get
51+ {
52+ return this . Parameters . GetValue < int > ( nameof ( this . MinimumIteration ) , 0 ) ;
53+ }
54+ }
55+
4556 /// <summary>
4657 /// Executes all of the child components continuously in parallel, respecting the specified timeout.
4758 /// </summary>
@@ -72,10 +83,17 @@ protected override Task ExecuteAsync(EventContext telemetryContext, Cancellation
7283 /// </summary>
7384 private async Task ExecuteComponentLoopAsync ( VirtualClientComponent component , EventContext telemetryContext , CancellationToken cancellationToken )
7485 {
86+ int iterationCount = 0 ;
7587 while ( ! cancellationToken . IsCancellationRequested )
7688 {
7789 try
7890 {
91+ if ( this . timeoutTask . IsCompleted )
92+ {
93+ this . Logger . LogMessage ( $ "Stopping { nameof ( ParallelLoopExecution ) } after Timeout of '{ this . Duration } '", LogLevel . Information , telemetryContext ) ;
94+ break ;
95+ }
96+
7997 string scenarioMessage = string . IsNullOrWhiteSpace ( component . Scenario )
8098 ? $ "{ nameof ( ParallelLoopExecution ) } Component = { component . TypeName } "
8199 : $ "{ nameof ( ParallelLoopExecution ) } Component = { component . TypeName } (scenario={ component . Scenario } )";
@@ -84,14 +102,19 @@ private async Task ExecuteComponentLoopAsync(VirtualClientComponent component, E
84102
85103 // Execute the component task with timeout handling.
86104 Task componentExecutionTask = component . ExecuteAsync ( cancellationToken ) ;
105+
87106 Task completedTask = await Task . WhenAny ( componentExecutionTask , this . timeoutTask ) ;
88107
89- if ( completedTask == this . timeoutTask )
108+ if ( completedTask == this . timeoutTask && iterationCount >= this . MinimumIteration )
90109 {
91110 break ;
92111 }
93112
94113 await componentExecutionTask ;
114+
115+ iterationCount ++ ;
116+
117+ this . Logger . LogMessage ( $ "Iteration { iterationCount } completed for component { component . TypeName } ", LogLevel . Information , telemetryContext ) ;
95118 }
96119 catch ( Exception ex )
97120 {
0 commit comments