Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests/Harness/SqlServerTestDatabaseTests.cs
T
Joseph Doherty 5aa7d24db6 test(sql): #1114 SQL test DB harnesses: 300 s migration / 60 s connect timeouts; retry once on a lost migration applock
Item 4: Configuration.Tests SchemaComplianceFixture + MigrationScratchDatabase
and AdminUI.Tests AdminUiSqlServerFixture get the same 300 s migration command /
60 s connect timeouts ControlPlane.Tests' SqlServerTestDatabase got in #1111.
(Server.Tests / Host.Tests have no SQL Server test-DB harness.)

Item 5: all three harnesses (and ControlPlane's) retry database creation ONCE
under a fresh database name when the migration fails with a lost
__EFMigrationsLock (SQL 1223, 'Cannot release the application lock ... not
currently held'), dropping the half-migrated database first. Any other failure
behaves as before. Recognition is unit-tested in ControlPlane.Tests.
2026-12-05 02:58:36 -05:00

26 lines
1.0 KiB
C#

using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Tests.Harness;
/// <summary>#1114: the harness retries DB creation once, but only on a lost migration applock.</summary>
public sealed class SqlServerTestDatabaseTests
{
[Fact]
public void A_lost_migration_applock_is_recognised_even_when_wrapped()
{
var lost = new InvalidOperationException(
"Cannot release the application lock (Database Principal: 'public', Resource: '__EFMigrationsLock') " +
"because it is not currently held.");
SqlServerTestDatabase.IsLostMigrationLock(lost).ShouldBeTrue();
SqlServerTestDatabase.IsLostMigrationLock(new Exception("migration failed", lost)).ShouldBeTrue();
}
[Fact]
public void Any_other_migration_failure_is_not_retried()
{
SqlServerTestDatabase.IsLostMigrationLock(new InvalidOperationException("Invalid column name 'X'.")).ShouldBeFalse();
SqlServerTestDatabase.IsLostMigrationLock(new TimeoutException("Execution Timeout Expired.")).ShouldBeFalse();
}
}