-
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 PurgeOrchestrationHistory
- Fix bug with PurgeOrchestrationHistory relating to null start date
- Loading branch information
1 parent
35cffa7
commit eebcb30
Showing
3 changed files
with
90 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
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
// 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 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) | ||
{ | ||
ILogger logger = executionContext.GetLogger("HelloCities_HttpStart"); | ||
|
||
logger.LogInformation("Starting purge all instance history"); | ||
|
||
var requestPurgeResult = await client.PurgeAllInstancesAsync(new PurgeInstancesFilter(null, DateTime.UtcNow, 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; | ||
} | ||
} | ||
} |
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,49 @@ | ||
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; | ||
} | ||
|
||
// Due to some kind of asynchronous race condition in XUnit, when running these tests in pipelines, | ||
// the output may be disposed before the message is written. Just ignore these types of errors for now. | ||
private void WriteOutput(string message) | ||
{ | ||
try | ||
{ | ||
_output.WriteLine(message); | ||
} | ||
catch | ||
{ | ||
// Ignore | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("PurgeOrchestrationHistory", HttpStatusCode.OK, @"^Purged [0-9]* records$")] | ||
public async Task HttpTriggerTests(string functionName, HttpStatusCode expectedStatusCode, string responseRegex) | ||
{ | ||
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger(functionName, ""); | ||
string actualMessage = await response.Content.ReadAsStringAsync(); | ||
Assert.Matches(responseRegex, actualMessage); | ||
Assert.Equal(expectedStatusCode, response.StatusCode); | ||
} | ||
} |