From f78f9cac281be9a56b6ca2f0609ae9c666b42bc4 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 17 Aug 2026 06:15:28 -0400 Subject: [PATCH] =?UTF-8?q?test(sql):=20route=20SchemaComplianceFixture.Di?= =?UTF-8?q?spose=20through=20the=20hardened=20TryDropDatabase=20=E2=80=94?= =?UTF-8?q?=20one=20drop-DDL=20shape=20per=20file=20(final-review=20carryo?= =?UTF-8?q?ver)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SchemaComplianceFixture.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/SchemaComplianceFixture.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/SchemaComplianceFixture.cs index 5e4c02b7..1ef229e8 100644 --- a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/SchemaComplianceFixture.cs +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/SchemaComplianceFixture.cs @@ -73,23 +73,19 @@ public sealed class SchemaComplianceFixture : IDisposable return SqlTestDatabaseReaper.ReapOrphans(master, TestDatabasePrefix, DateTime.UtcNow - OrphanAge).Count; } - /// Disposes the fixture and drops the test database. + /// + /// Disposes the fixture and drops the test database — via the same parameterized + /// the reaper uses, so this file carries + /// exactly one drop-DDL shape. Best-effort like the AdminUI fixture's teardown: the name is + /// self-minted so a swallowed failure only leaks a database the startup reaper reclaims + /// within 24 h. + /// public void Dispose() { var masterConnection = new SqlConnectionStringBuilder(ConnectionString) { InitialCatalog = "master" }.ConnectionString; - using var conn = new SqlConnection(masterConnection); - conn.Open(); - - using var cmd = conn.CreateCommand(); - cmd.CommandText = $@" -IF DB_ID(N'{DatabaseName}') IS NOT NULL -BEGIN - ALTER DATABASE [{DatabaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; - DROP DATABASE [{DatabaseName}]; -END"; - cmd.ExecuteNonQuery(); + SqlTestDatabaseReaper.TryDropDatabase(masterConnection, DatabaseName); } }