@@ -125,6 +125,42 @@ public async Task PurgesInstancesByStatus(OrchestrationStateTimeRangeFilterType
125125 await this . testService . PurgeAsync ( DateTime . MaxValue , filterType ) ;
126126 }
127127
128+ /// <summary>
129+ /// Verifies that PurgeInstanceStateAsync with a PurgeInstanceFilter purges all matching instances,
130+ /// even when the count exceeds the previous 1000-instance limit.
131+ /// This is a regression test for https://github.com/microsoft/durabletask-mssql/issues/297.
132+ /// </summary>
133+ [ Fact ]
134+ public async Task PurgesMoreThanOneThousandInstances ( )
135+ {
136+ const int InstanceCount = 1100 ;
137+
138+ IReadOnlyList < TestInstance < string > > instances = await this . testService . RunOrchestrations (
139+ count : InstanceCount ,
140+ instanceIdGenerator : i => $ "BulkPurge_{ i : 0000} ",
141+ inputGenerator : i => $ "Input_{ i } ",
142+ orchestrationName : "QuickComplete" ,
143+ version : string . Empty ,
144+ implementation : ( ctx , input ) => Task . FromResult ( input ) ) ;
145+
146+ TimeSpan timeout = TimeSpan . FromSeconds ( 60 ) ;
147+ await Task . WhenAll ( instances . Select ( instance => instance . WaitForCompletion ( timeout ) ) ) ;
148+
149+ var filter = new PurgeInstanceFilter (
150+ DateTime . MinValue ,
151+ DateTime . UtcNow . AddMinutes ( 1 ) ,
152+ new [ ] { OrchestrationStatus . Completed } ) ;
153+
154+ PurgeResult result = await this . testService . PurgeAsync ( filter ) ;
155+ Assert . Equal ( InstanceCount , result . DeletedInstanceCount ) ;
156+
157+ foreach ( TestInstance < string > instance in instances )
158+ {
159+ OrchestrationState purgedState = await instance . GetStateAsync ( ) ;
160+ Assert . Null ( purgedState ) ;
161+ }
162+ }
163+
128164 /// <summary>
129165 /// Validates that external events sent to a completed orchestration are eventually removed from the database
130166 /// and that a log message is emitted for each discarded event.
0 commit comments