Skip to content

Commit b1d1d25

Browse files
committed
Try async middleware testing
Signed-off-by: Hal Spang <[email protected]>
1 parent bfdbf8d commit b1d1d25

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

test/e2e/Apps/BasicDotNetIsolated/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
using System.Diagnostics;
99

1010
var host = new HostBuilder()
11-
.ConfigureFunctionsWebApplication()
11+
.ConfigureFunctionsWebApplication(workerApplication =>
12+
{
13+
// Register async middleware to test the fix for https://github.com/microsoft/durabletask-dotnet/issues/158
14+
// This middleware performs async operations that previously caused non-determinism exceptions
15+
workerApplication.UseMiddleware<Microsoft.Azure.Durable.Tests.E2E.TestAsyncMiddleware>();
16+
})
1217
.ConfigureServices(services => {
1318
services.AddApplicationInsightsTelemetryWorkerService();
1419
services.ConfigureFunctionsApplicationInsights();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.Azure.Functions.Worker;
7+
using Microsoft.Azure.Functions.Worker.Middleware;
8+
9+
namespace Microsoft.Azure.Durable.Tests.E2E;
10+
11+
/// <summary>
12+
/// Test middleware that performs async operations to validate the fix for
13+
/// https://github.com/microsoft/durabletask-dotnet/issues/158
14+
/// This middleware simulates async behaviors like App Configuration or logging services.
15+
/// </summary>
16+
public class TestAsyncMiddleware : IFunctionsWorkerMiddleware
17+
{
18+
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next)
19+
{
20+
// Simulate an async operation like fetching configuration or logging
21+
await Task.Delay(1);
22+
23+
// Store metadata to verify the middleware ran
24+
context.Items["AsyncMiddlewareExecuted"] = true;
25+
context.Items["AsyncMiddlewareTimestamp"] = DateTime.UtcNow;
26+
27+
// Continue to the next middleware/function
28+
await next(context);
29+
30+
// Simulate async post-processing
31+
await Task.Delay(1);
32+
}
33+
}

0 commit comments

Comments
 (0)