-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for PurgeAllInstancesAsync (#3021)
- Add a test for PurgeOrchestrationHistory - Fix bug with PurgeOrchestrationHistory relating to null start date
- Loading branch information
1 parent
168d7d0
commit c838aa0
Showing
4 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/e2e/Apps/BasicDotNetIsolated/PurgeOrchestrationHistory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Net; | ||
using Grpc.Core; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.DurableTask.Client; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.Durable.Tests.E2E | ||
{ | ||
public static class PurgeOrchestrationHistory | ||
{ | ||
[Function(nameof(PurgeOrchestrationHistory))] | ||
public static async Task<HttpResponseData> PurgeHistory( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req, | ||
[DurableClient] DurableTaskClient client, | ||
FunctionContext executionContext, | ||
DateTime? purgeStartTime=null, | ||
DateTime? purgeEndTime=null) | ||
{ | ||
ILogger logger = executionContext.GetLogger("HelloCities_HttpStart"); | ||
|
||
logger.LogInformation("Starting purge all instance history"); | ||
try | ||
{ | ||
var requestPurgeResult = await client.PurgeAllInstancesAsync(new PurgeInstancesFilter(purgeStartTime, purgeEndTime, new List<OrchestrationRuntimeStatus>{ | ||
OrchestrationRuntimeStatus.Completed, | ||
OrchestrationRuntimeStatus.Failed, | ||
OrchestrationRuntimeStatus.Terminated | ||
})); | ||
|
||
logger.LogInformation("Finished purge all instance history"); | ||
|
||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
response.Headers.Add("Content-Type", "text/plain"); | ||
await response.WriteStringAsync($"Purged {requestPurgeResult.PurgedInstanceCount} records"); | ||
return response; | ||
} | ||
catch (RpcException ex) | ||
{ | ||
logger.LogError(ex, "Failed to purge all instance history"); | ||
var response = req.CreateResponse(HttpStatusCode.InternalServerError); | ||
response.Headers.Add("Content-Type", "text/plain"); | ||
await response.WriteStringAsync($"Failed to purge all instance history: {ex.Message}"); | ||
return response; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.Azure.Durable.Tests.DotnetIsolatedE2E; | ||
|
||
[Collection(Constants.FunctionAppCollectionName)] | ||
public class PurgeInstancesTests | ||
{ | ||
private readonly FunctionAppFixture _fixture; | ||
private readonly ITestOutputHelper _output; | ||
|
||
public PurgeInstancesTests(FunctionAppFixture fixture, ITestOutputHelper testOutputHelper) | ||
{ | ||
_fixture = fixture; | ||
_fixture.TestLogs.UseTestLogger(testOutputHelper); | ||
_output = testOutputHelper; | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeOrchestrationHistory_StartAndEnd_Succeeds() | ||
{ | ||
DateTime purgeStartTime = DateTime.MinValue; | ||
DateTime purgeEndTime = DateTime.UtcNow; | ||
string queryParams = $"?purgeStartTime={purgeStartTime:o}&purgeEndTime={purgeEndTime:o}"; | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", queryParams); | ||
string actualMessage = await response.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", actualMessage); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeOrchestrationHistory_Start_Succeeds() | ||
{ | ||
DateTime purgeStartTime = DateTime.MinValue; | ||
DateTime purgeEndTime = DateTime.UtcNow; | ||
string queryParams = $"?purgeStartTime={purgeStartTime:o}"; | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", queryParams); | ||
string actualMessage = await response.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", actualMessage); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeOrchestrationHistory_End_Succeeds() | ||
{ | ||
DateTime purgeStartTime = DateTime.MinValue; | ||
DateTime purgeEndTime = DateTime.UtcNow; | ||
string queryParams = $"?purgeEndTime={purgeEndTime:o}"; | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", queryParams); | ||
string actualMessage = await response.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", actualMessage); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeOrchestrationHistory_NoBoundaries_Succeeds() | ||
{ | ||
DateTime purgeStartTime = DateTime.MinValue; | ||
DateTime purgeEndTime = DateTime.UtcNow; | ||
string queryParams = $""; | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", queryParams); | ||
string actualMessage = await response.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", actualMessage); | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeOrchestrationHistoryAfterInvocation_Succeeds() | ||
{ | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("HelloCities_HttpStart", ""); | ||
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
Thread.Sleep(1000); | ||
|
||
DateTime purgeEndTime = DateTime.UtcNow + TimeSpan.FromMinutes(1); | ||
using HttpResponseMessage purgeResponse = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", $"?purgeEndTime={purgeEndTime:o}"); | ||
string purgeMessage = await purgeResponse.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", purgeMessage); | ||
Assert.DoesNotMatch(@"^Purged 0 records$", purgeMessage); | ||
Assert.Equal(HttpStatusCode.OK, purgeResponse.StatusCode); | ||
} | ||
|
||
[Fact] | ||
public async Task PurgeAfterPurge_ZeroRows() | ||
{ | ||
DateTime purgeEndTime = DateTime.UtcNow + TimeSpan.FromMinutes(1); | ||
using HttpResponseMessage purgeResponse = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", $"?purgeEndTime={purgeEndTime:o}"); | ||
string purgeMessage = await purgeResponse.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged [0-9]* records$", purgeMessage); | ||
using HttpResponseMessage purgeAgainResponse = await HttpHelpers.InvokeHttpTrigger("PurgeOrchestrationHistory", $"?purgeEndTime={purgeEndTime:o}"); | ||
string purgeAgainMessage = await purgeAgainResponse.Content.ReadAsStringAsync(); | ||
Assert.Matches(@"^Purged 0 records$", purgeAgainMessage); | ||
Assert.Equal(HttpStatusCode.OK, purgeAgainResponse.StatusCode); | ||
} | ||
} |