From 177131b09c05c56c01aa990ff373b6219cb5f3c3 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 9 Aug 2026 05:03:26 -0700 Subject: [PATCH 1/2] Switches integration tests to per-factory shared in-memory SQLite databases Instead of sharing a single SQLite connection across all DbContexts within a factory, each factory now opens its own uniquely named shared in-memory database, so that every DbContext gets its own pooled connection. This prevents nested transaction errors caused by a cancelled request leaving a transaction open on the shared connection, since the connection is no longer reused across DbContexts, and keeps parallel test classes isolated from one another. --- .../Common/Setup/LuminaApiFactory.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs index 9f270518..ed336790 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs @@ -26,7 +26,9 @@ namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup; public class LuminaApiFactory : WebApplicationFactory, IDisposable { private readonly SqliteConnection _connection; + private readonly string _sharedInMemoryConnectionString; private const string TEST_ENCRYPTION_KEY = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="; + private const string SHARED_IN_MEMORY_CONNECTION_STRING_PREFIX = "Data Source=lumina-tests-{0};Mode=Memory;Cache=Shared"; private static byte s_IpClass = 25; public static byte IpClass => s_IpClass++; @@ -36,7 +38,12 @@ public class LuminaApiFactory : WebApplicationFactory, IDisposable /// public LuminaApiFactory() { - _connection = new SqliteConnection("DataSource=:memory:"); + // each factory gets its own uniquely named shared in-memory database, so that parallel test classes remain isolated from one another; + // the shared cache allows each DbContext to open its own pooled connection to the same database, instead of sharing a single connection, + // which would otherwise serialize every request on one connection and cause nested transaction errors between requests + _sharedInMemoryConnectionString = string.Format(SHARED_IN_MEMORY_CONNECTION_STRING_PREFIX, Guid.NewGuid()); + // keep a single anchor connection open, so that the shared in-memory database it refers to is not dropped + _connection = new SqliteConnection(_sharedInMemoryConnectionString); _connection.Open(); } @@ -73,7 +80,7 @@ public class LuminaApiFactory : WebApplicationFactory, IDisposable // add SQLite DbContext configuration services.AddDbContext((serviceProvider, options) => { - options.UseSqlite(_connection); + options.UseSqlite(_sharedInMemoryConnectionString); options.AddInterceptors(serviceProvider.GetRequiredService()); }); // configure JWT authentication for testing From 8a8bdecc7c1e914a2f9616eb9ff531b132389446 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 9 Aug 2026 05:05:18 -0700 Subject: [PATCH 2/2] Increases the SQLite busy timeout to 30 seconds Raises the busy timeout used when opening the SQLite connection from 10 to 30 seconds, so that the Entity Framework connection and the dedicated connections used by the bulk data access operations of Dapper keep retrying for longer instead of failing with database locking errors during concurrent access. --- src/Lumina.Presentation.Api/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lumina.Presentation.Api/Program.cs b/src/Lumina.Presentation.Api/Program.cs index 35fb28a5..3e3482bb 100644 --- a/src/Lumina.Presentation.Api/Program.cs +++ b/src/Lumina.Presentation.Api/Program.cs @@ -93,7 +93,7 @@ public class Program SqliteConnection sqliteConnection = new(context.Database.GetDbConnection().ConnectionString); sqliteConnection.Open(); using SqliteCommand sqliteCommand = sqliteConnection.CreateCommand(); - sqliteCommand.CommandText = "PRAGMA journal_mode=WAL; PRAGMA busy_timeout=10000;"; + sqliteCommand.CommandText = "PRAGMA journal_mode=WAL; PRAGMA busy_timeout=30000;"; sqliteCommand.ExecuteNonQuery(); sqliteConnection.Close(); }