From bb321a8a498ef9ee45b4fd1b6aef24cf9816f504 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 2 Dec 2025 13:30:24 +0100 Subject: [PATCH] Remove `IntegrationTestSample.cs` and related README while updating package dependencies. --- Directory.Packages.props | 87 ++++++++++++++++++---------- src/samples/IntegrationTestSample.cs | 59 ------------------- src/samples/README.md | 26 --------- 3 files changed, 58 insertions(+), 114 deletions(-) delete mode 100644 src/samples/IntegrationTestSample.cs delete mode 100644 src/samples/README.md diff --git a/Directory.Packages.props b/Directory.Packages.props index 556ab5999..25b0c095e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,6 +13,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -24,6 +53,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -63,36 +121,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -135,8 +166,6 @@ - - diff --git a/src/samples/IntegrationTestSample.cs b/src/samples/IntegrationTestSample.cs deleted file mode 100644 index be626239f..000000000 --- a/src/samples/IntegrationTestSample.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Threading.Tasks; -using Elsa.Testing.Extensions; -using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.Extensions.Hosting; -using Xunit; - -namespace Sample; - -/// -/// Sample integration test showing how to properly shutdown Elsa background tasks. -/// -/// The startup class of your application. -public class IntegrationTestBase : IAsyncDisposable where TStartup : class -{ - protected readonly WebApplicationFactory Factory; - - public IntegrationTestBase() - { - Factory = new WebApplicationFactory(); - // ... other initialization code - } - - public async ValueTask DisposeAsync() - { - // Explicitly stop Elsa background tasks before disposing the factory - await Factory.ShutdownElsaAsync(); - - // Then stop the server and host - if (Factory.Server?.Host != null) - { - await Factory.Server.Host.StopAsync(); - } - - Factory.Dispose(); - GC.SuppressFinalize(this); - } -} - -/// -/// Example test class inheriting from the base integration test class. -/// -public class ExampleIntegrationTest : IntegrationTestBase -{ - [Fact] - public async Task SampleTest() - { - // Test logic here - await Task.CompletedTask; - } -} - -/// -/// Sample startup class for demonstration purposes. -/// -public class TestStartup -{ - // This is just a placeholder class for the example -} \ No newline at end of file diff --git a/src/samples/README.md b/src/samples/README.md deleted file mode 100644 index 20c408b89..000000000 --- a/src/samples/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Elsa Integration Testing Examples - -This directory contains samples and examples showing best practices for integration testing with Elsa Workflows. - -## Properly Shutting Down Elsa Background Tasks in Integration Tests - -When using ASP.NET Core's `WebApplicationFactory` in integration tests with Elsa Workflows, it's important to properly shut down Elsa's background tasks before disposing the factory. Failure to do so can result in task crashes and errors when the test host is stopped, especially if your test drops or disposes databases. - -### The Issue - -Elsa uses background tasks and recurring tasks for various purposes, such as bookmark processing and workflow execution. These tasks continue running in the background, and when the test host is abruptly shut down without properly deactivating them, they may attempt to access resources (like databases) that have already been disposed or dropped, resulting in errors. - -### The Solution - -The `WebApplicationFactoryExtensions` class provides an extension method `ShutdownElsaAsync` that properly shuts down all Elsa background tasks by deactivating the tenants. This should be called in your test teardown code before stopping and disposing the factory. - -```csharp -// In your test's Dispose or DisposeAsync method: -await factory.ShutdownElsaAsync(); -``` - -See the `IntegrationTestSample.cs` file for a complete example of a base test class that properly handles Elsa shutdown. - -### Best Practice - -Always shut down Elsa tasks explicitly before stopping and disposing your `WebApplicationFactory` in integration tests, especially if your test uses real databases that might be dropped after each test. \ No newline at end of file