From 77bc52ed28e16dab983044fb800aea7a5a87e8d0 Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 25 Apr 2026 15:04:32 +0800 Subject: [PATCH] Address Copilot review feedback --- ...SeparateDbEntityFrameworkCoreTestModule.cs | 22 +++++++++++-------- ...nager_SharedUser_SeparateDatabase_Tests.cs | 16 ++++++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs b/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs index e6c624852b..1b5ce037a1 100644 --- a/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs +++ b/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Concurrent; +using System.Collections.Generic; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -31,10 +31,10 @@ public class AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule : AbpM public static readonly Guid TenantBId = IdentityUserManager_SharedUser_SeparateDatabase_Tests.TenantBId; - // Static cache so the in-memory SQLite databases survive for the full process lifetime - // (without an open connection, in-memory shared-cache databases are discarded). One entry - // per unique connection string. - private static readonly ConcurrentDictionary _keepAlive = new(); + // Per-app keep-alive connections so the in-memory SQLite databases survive for the test's + // lifetime (without an open connection, shared-cache in-memory databases are discarded). + // Disposed in OnApplicationShutdown so connections do not accumulate across tests. + private readonly List _keepAlive = new(); public override void PreConfigureServices(ServiceConfigurationContext context) { @@ -98,16 +98,20 @@ public class AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule : AbpM context.Services.AddAlwaysDisableUnitOfWorkTransaction(); } - private static void EnsureDatabase(string connectionString) + public override void OnApplicationShutdown(ApplicationShutdownContext context) { - if (_keepAlive.ContainsKey(connectionString)) + foreach (var connection in _keepAlive) { - return; + connection.Dispose(); } + _keepAlive.Clear(); + } + private void EnsureDatabase(string connectionString) + { var keepAlive = new SqliteConnection(connectionString); keepAlive.Open(); - _keepAlive[connectionString] = keepAlive; + _keepAlive.Add(keepAlive); new IdentityDbContext( new DbContextOptionsBuilder().UseSqlite(connectionString).Options) diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs index 3a965d5838..ce7128c5d2 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs @@ -120,11 +120,15 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests