Problem
The LocalDB optimization (AUTO_UPDATE_STATISTICS_ASYNC ON) has exposed 34+ latent race conditions where database objects with FK dependencies are created without intermediate commits.
Root Cause
With async statistics enabled, INSERT operations may not be immediately visible to subsequent FK constraint checks. When parent-child objects are created in rapid succession:
// RISKY
var parent = new TableInfo(repo, "Table");
var child = new ColumnInfo(repo, "Column", "int", parent); // FK check may fail
Impact
- Tests: Intermittent failures ("FK constraint violation")
- Production: At least one production code path affected
- CI: Timing-dependent failures hard to debug
Affected FK Relationships
TableInfo → ColumnInfo
Catalogue → CatalogueItem
CatalogueItem → ExtractionInformation
ColumnInfo → ExtractionInformation
Locations (34+ instances)
Priority 1 (Highest Impact)
Tests.Common/UnitTests.cs - Helper methods used by all tests
Rdmp.Core/CommandExecution/ExecuteCommandCreateNewCohortFromTable.cs - PRODUCTION CODE
AggregateBuilderTestsBase.cs - Affects many test classes
Priority 2 (Individual Tests)
- 30+ test files with SetUp methods or test code
Solution Pattern
// SAFE
var parent = new TableInfo(repo, "Table");
parent.SaveToDatabase(); // Explicit commit
var child = new ColumnInfo(repo, "Column", "int", parent);
Action Plan
Already Fixed
- ✅
Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.cs
Related
- Exposed by commit: a1ee79e (LocalDB optimization with async statistics)
- Branch: fix/bundle-build-workflow
Problem
The LocalDB optimization (
AUTO_UPDATE_STATISTICS_ASYNC ON) has exposed 34+ latent race conditions where database objects with FK dependencies are created without intermediate commits.Root Cause
With async statistics enabled, INSERT operations may not be immediately visible to subsequent FK constraint checks. When parent-child objects are created in rapid succession:
Impact
Affected FK Relationships
TableInfo → ColumnInfoCatalogue → CatalogueItemCatalogueItem → ExtractionInformationColumnInfo → ExtractionInformationLocations (34+ instances)
Priority 1 (Highest Impact)
Tests.Common/UnitTests.cs- Helper methods used by all testsRdmp.Core/CommandExecution/ExecuteCommandCreateNewCohortFromTable.cs- PRODUCTION CODEAggregateBuilderTestsBase.cs- Affects many test classesPriority 2 (Individual Tests)
Solution Pattern
Action Plan
Tests.Common/UnitTests.cshelper methodsExecuteCommandCreateNewCohortFromTable.csAggregateBuilderTestsBase.cs, etc.)Already Fixed
Rdmp.Core.Tests/CohortCommitting/CreateNewCohortDatabaseWizardTests.csRelated