From ab4845b9418430cefe5592e3e01b5a2ed9a8631a Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Sat, 16 May 2026 12:50:26 +0100 Subject: [PATCH] Enable SQL retry, update test config, disable parallelism Updated DbContext to enable SQL retry on failure. Refactored CustomWebApplicationFactory for clarity and added in-memory connection string settings. Disabled parallel test execution in xunit.runner.json for improved test reliability. --- EstateReportingAPI.BusinessLogic/QueryTimingInterceptor.cs | 2 +- .../CustomWebApplicationFactory.cs | 6 +++--- EstateReportingAPI.IntegrationTests/xunit.runner.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/EstateReportingAPI.BusinessLogic/QueryTimingInterceptor.cs b/EstateReportingAPI.BusinessLogic/QueryTimingInterceptor.cs index 7c8835a..f07b6f5 100644 --- a/EstateReportingAPI.BusinessLogic/QueryTimingInterceptor.cs +++ b/EstateReportingAPI.BusinessLogic/QueryTimingInterceptor.cs @@ -84,7 +84,7 @@ public ResolvedDbContext Resolve(String connectionStringKey, // Create an isolated service collection and provider ServiceCollection services = new(); services.AddDbContext(options => { - options.UseSqlServer(connectionString); + options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure()); options.AddInterceptors(Interceptor); // attach here }); diff --git a/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs b/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs index f09be04..4339b0b 100644 --- a/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs +++ b/EstateReportingAPI.IntegrationTests/CustomWebApplicationFactory.cs @@ -52,7 +52,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) containerBuilder.AddTransient(_ => context); var serviceProvider = containerBuilder.BuildServiceProvider(); - + var inMemorySettings = new Dictionary { { "ConnectionStrings:TransactionProcessorReadModel", DatabaseConnectionString } @@ -71,8 +71,8 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) containerBuilder.AddAuthentication(TestAuthHandler.AuthenticationScheme) .AddScheme(TestAuthHandler.AuthenticationScheme, options => { }); - - + + }); } diff --git a/EstateReportingAPI.IntegrationTests/xunit.runner.json b/EstateReportingAPI.IntegrationTests/xunit.runner.json index 29ceb58..a4c61e5 100644 --- a/EstateReportingAPI.IntegrationTests/xunit.runner.json +++ b/EstateReportingAPI.IntegrationTests/xunit.runner.json @@ -1,4 +1,4 @@ { - "maxParallelThreads": 3, - "parallelizeTestCollections": true + "maxParallelThreads": 1, + "parallelizeTestCollections": false } \ No newline at end of file