Skip to content

Commit 951d857

Browse files
committed
Add end-to-end tests for PurgeInstance and PurgeInstances_WithFilter methods in GrpcDurableTaskClientIntegrationTests. These tests verify the correct behavior of instance purging and ensure instances are removed as expected.
1 parent 332f35d commit 951d857

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/Grpc.IntegrationTests/GrpcDurableTaskClientIntegrationTests.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,80 @@ await server.Client.ScheduleNewOrchestrationInstanceAsync(
150150
page.ContinuationToken.Should().NotBeNull();
151151
}
152152

153+
[Fact]
154+
public async Task PurgeInstance_EndToEnd()
155+
{
156+
// Arrange
157+
await using HostTestLifetime server = await this.StartAsync();
158+
159+
// Create and complete an orchestration instance
160+
string instanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(
161+
OrchestrationName, input: false);
162+
163+
// Wait for it to start and raise event to complete it
164+
await server.Client.WaitForInstanceStartAsync(instanceId, default);
165+
await server.Client.RaiseEventAsync(instanceId, "event", default);
166+
await server.Client.WaitForInstanceCompletionAsync(instanceId, default);
167+
168+
// Verify instance exists before purge
169+
OrchestrationMetadata? metadata = await server.Client.GetInstanceAsync(instanceId, false);
170+
metadata.Should().NotBeNull();
171+
metadata!.InstanceId.Should().Be(instanceId);
172+
metadata.RuntimeStatus.Should().Be(OrchestrationRuntimeStatus.Completed);
173+
174+
// Act
175+
PurgeResult result = await server.Client.PurgeInstanceAsync(
176+
instanceId,
177+
new PurgeInstanceOptions { Recursive = true });
178+
179+
// Assert
180+
result.Should().NotBeNull();
181+
result.PurgedInstanceCount.Should().Be(1);
182+
result.IsComplete.Should().BeNull();
183+
// Verify instance no longer exists
184+
OrchestrationMetadata? instance = await server.Client.GetInstanceAsync(instanceId, false);
185+
instance.Should().BeNull();
186+
}
187+
188+
[Fact]
189+
public async Task PurgeInstances_WithFilter_EndToEnd()
190+
{
191+
// Arrange
192+
await using HostTestLifetime server = await this.StartAsync();
193+
List<string> instanceIds = new List<string>();
194+
195+
// Create multiple instances
196+
for (int i = 0; i < 3; i++)
197+
{
198+
string instanceId = await server.Client.ScheduleNewOrchestrationInstanceAsync(
199+
OrchestrationName, input: false);
200+
instanceIds.Add(instanceId);
201+
202+
// Wait for it to start and raise event to complete it
203+
await server.Client.WaitForInstanceStartAsync(instanceId, default);
204+
await server.Client.RaiseEventAsync(instanceId, "event", default);
205+
await server.Client.WaitForInstanceCompletionAsync(instanceId, default);
206+
}
207+
208+
// Act
209+
PurgeResult result = await server.Client.PurgeAllInstancesAsync(
210+
new PurgeInstancesFilter(
211+
CreatedFrom: DateTime.UtcNow.AddMinutes(-5),
212+
CreatedTo: DateTime.UtcNow,
213+
Statuses: new[] { OrchestrationRuntimeStatus.Completed }));
214+
215+
// Assert
216+
result.Should().NotBeNull();
217+
result.PurgedInstanceCount.Should().BeGreaterThan(3);
218+
result.IsComplete.Should().BeNull();
219+
// Verify instances no longer exist
220+
foreach (string instanceId in instanceIds)
221+
{
222+
OrchestrationMetadata? instance = await server.Client.GetInstanceAsync(instanceId, false);
223+
instance.Should().BeNull();
224+
}
225+
}
226+
153227
Task<HostTestLifetime> StartAsync()
154228
{
155229
static async Task<string> Orchestration(TaskOrchestrationContext context, bool shouldThrow)

0 commit comments

Comments
 (0)