From 9ecbb3f3601d2889c3ac7205c7cb46dd8c8cae24 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 1 Nov 2024 18:02:47 +0100 Subject: [PATCH] Comment out scope disposal and update server configurations Commented out Scope disposal to prevent test runner hangs in component tests. Adjusted Cluster class to use property initializers instead of constructor. Updated workflow server connection strings and added detailed SQL Server configuration in Program.cs. --- src/apps/Elsa.Server.Web/Program.cs | 8 ++++++- .../Abstractions/AppComponentTest.cs | 19 +++++++++------- .../AzureServiceBusTests.cs | 2 +- .../Fixtures/App.cs | 2 +- .../Helpers/Abstractions/AppComponentTest.cs | 4 +++- .../Helpers/Fixtures/Cluster.cs | 22 ++++--------------- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/apps/Elsa.Server.Web/Program.cs b/src/apps/Elsa.Server.Web/Program.cs index 36855e779..0ec35c509 100644 --- a/src/apps/Elsa.Server.Web/Program.cs +++ b/src/apps/Elsa.Server.Web/Program.cs @@ -7,6 +7,7 @@ using Elsa.Common.RecurringTasks; using Elsa.Dapper.Extensions; using Elsa.Dapper.Services; using Elsa.DropIns.Extensions; +using Elsa.EntityFrameworkCore; using Elsa.EntityFrameworkCore.Extensions; using Elsa.EntityFrameworkCore.Modules.Alterations; using Elsa.EntityFrameworkCore.Modules.Identity; @@ -226,7 +227,12 @@ services runtime.UseEntityFrameworkCore(ef => { if (sqlDatabaseProvider == SqlDatabaseProvider.SqlServer) - ef.UseSqlServer(sqlServerConnectionString!); + { + //ef.UseSqlServer(sqlServerConnectionString, new ElsaDbContextOptions); + var migrationsAssembly = typeof(Elsa.EntityFrameworkCore.SqlServer.IdentityDbContextFactory).Assembly; + var connectionString = sqlServerConnectionString; + ef.DbContextOptionsBuilder = (_, db) => db.UseElsaSqlServer(migrationsAssembly, connectionString, null, configure => configure.CommandTimeout(60000)); + } else if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql) ef.UsePostgreSql(postgresConnectionString!); else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) diff --git a/test/component/Elsa.AzureServiceBus.ComponentTests/Abstractions/AppComponentTest.cs b/test/component/Elsa.AzureServiceBus.ComponentTests/Abstractions/AppComponentTest.cs index 29ef846e3..f0b77831d 100644 --- a/test/component/Elsa.AzureServiceBus.ComponentTests/Abstractions/AppComponentTest.cs +++ b/test/component/Elsa.AzureServiceBus.ComponentTests/Abstractions/AppComponentTest.cs @@ -3,19 +3,22 @@ namespace Elsa.AzureServiceBus.ComponentTests; [Collection(nameof(ServiceBusAppCollection))] -public abstract class AppComponentTest(App app) : IDisposable +public abstract class AppComponentTest(App app) : IDisposable //IAsyncLifetime { protected WorkflowServer WorkflowServer { get; } = app.WorkflowServer; protected Infrastructure Infrastructure { get; } = app.Infrastructure; - protected IServiceScope Scope { get; } = app.WorkflowServer.Services.CreateScope(); + protected IServiceScope Scope { get; private set; } = app.WorkflowServer.Services.CreateScope(); + public void Dispose() + { + // Disposing the Scope here and in other places where it is created somehow seems to cause the test runner to hang when running other test projects. + // Let's comment it out for the time being. + //Scope.Dispose(); + + OnDispose(); + } + protected virtual void OnDispose() { } - - void IDisposable.Dispose() - { - Scope.Dispose(); - OnDispose(); - } } \ No newline at end of file diff --git a/test/component/Elsa.AzureServiceBus.ComponentTests/AzureServiceBusTests.cs b/test/component/Elsa.AzureServiceBus.ComponentTests/AzureServiceBusTests.cs index 6f6d4ac2e..486604c10 100644 --- a/test/component/Elsa.AzureServiceBus.ComponentTests/AzureServiceBusTests.cs +++ b/test/component/Elsa.AzureServiceBus.ComponentTests/AzureServiceBusTests.cs @@ -34,7 +34,7 @@ public class AzureServiceBusTests : AppComponentTest [Fact] public async Task WorkflowReceivesMessage_WhenSendingMessageToTopic() { - var client = Scope.ServiceProvider.GetRequiredService(); + await using var client = Scope.ServiceProvider.GetRequiredService(); var topic = MessageReceivedTriggerWorkflow.Topic; diff --git a/test/component/Elsa.AzureServiceBus.ComponentTests/Fixtures/App.cs b/test/component/Elsa.AzureServiceBus.ComponentTests/Fixtures/App.cs index d59a1b049..d28195921 100644 --- a/test/component/Elsa.AzureServiceBus.ComponentTests/Fixtures/App.cs +++ b/test/component/Elsa.AzureServiceBus.ComponentTests/Fixtures/App.cs @@ -5,7 +5,7 @@ public class App : IAsyncLifetime public App() { Infrastructure = new(); - WorkflowServer = new(Infrastructure, "http://localhost:5001"); + WorkflowServer = new(Infrastructure, "http://localhost:5004"); } public Infrastructure Infrastructure { get; set; } diff --git a/test/component/Elsa.Workflows.ComponentTests/Helpers/Abstractions/AppComponentTest.cs b/test/component/Elsa.Workflows.ComponentTests/Helpers/Abstractions/AppComponentTest.cs index ea036f9e4..e69423a11 100644 --- a/test/component/Elsa.Workflows.ComponentTests/Helpers/Abstractions/AppComponentTest.cs +++ b/test/component/Elsa.Workflows.ComponentTests/Helpers/Abstractions/AppComponentTest.cs @@ -12,7 +12,9 @@ public abstract class AppComponentTest(App app) : IDisposable void IDisposable.Dispose() { - Scope.Dispose(); + // Disposing the Scope here and in other places where it is created somehow seems to cause the test runner to hang when running other test projects. + // Let's comment it out for the time being. + //Scope.Dispose(); OnDispose(); } diff --git a/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Cluster.cs b/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Cluster.cs index 1dd61b6a4..e07388593 100644 --- a/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Cluster.cs +++ b/test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Cluster.cs @@ -3,25 +3,11 @@ using Hangfire.Annotations; namespace Elsa.Workflows.ComponentTests.Helpers; [UsedImplicitly] -public class Cluster : IDisposable, IAsyncDisposable +public class Cluster(Infrastructure infrastructure) : IAsyncDisposable { - public Cluster(Infrastructure infrastructure) - { - Pod1 = new(infrastructure, "http://localhost:5001"); - Pod2 = new(infrastructure, "http://localhost:5002"); - Pod3 = new(infrastructure, "http://localhost:5003"); - } - - public WorkflowServer Pod3 { get; set; } - public WorkflowServer Pod2 { get; set; } - public WorkflowServer Pod1 { get; set; } - - public void Dispose() - { - Pod3.Dispose(); - Pod2.Dispose(); - Pod1.Dispose(); - } + public WorkflowServer Pod3 { get; set; } = new(infrastructure, "http://localhost:5003"); + public WorkflowServer Pod2 { get; set; } = new(infrastructure, "http://localhost:5002"); + public WorkflowServer Pod1 { get; set; } = new(infrastructure, "http://localhost:5001"); public async ValueTask DisposeAsync() {