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.
This commit is contained in:
Sipke Schoorstra 2024-11-01 18:02:47 +01:00
parent ab7fcbc334
commit 9ecbb3f360
6 changed files with 27 additions and 30 deletions

View file

@ -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)

View file

@ -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();
}
}

View file

@ -34,7 +34,7 @@ public class AzureServiceBusTests : AppComponentTest
[Fact]
public async Task WorkflowReceivesMessage_WhenSendingMessageToTopic()
{
var client = Scope.ServiceProvider.GetRequiredService<ServiceBusClient>();
await using var client = Scope.ServiceProvider.GetRequiredService<ServiceBusClient>();
var topic = MessageReceivedTriggerWorkflow.Topic;

View file

@ -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; }

View file

@ -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();
}

View file

@ -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()
{