From bd345ae949a9b4e47b58853a82f604742449d747 Mon Sep 17 00:00:00 2001 From: Meysam Hadeli <35596795+meysamhadeli@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:33:06 +0330 Subject: [PATCH] fix: try to fix failed tests in ci --- src/BuildingBlocks/PersistMessageProcessor/Extensions.cs | 5 ++++- .../PersistMessageBackgroundService.cs | 7 ++----- src/BuildingBlocks/TestBase/TestBase.cs | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs index 5aef3604..1efc84a4 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs @@ -51,7 +51,10 @@ IWebHostEnvironment env services.AddScoped(); - services.AddHostedService(); + if (env.EnvironmentName != "test") + { + services.AddHostedService(); + } return services; } diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs index 68f40925..7ec8f646 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageBackgroundService.cs @@ -14,15 +14,12 @@ IOptions options { private PersistMessageOptions _options = options.Value; - private Task? _executingTask; - - protected override Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { logger.LogInformation("PersistMessage Background Service Start"); - _executingTask = ProcessAsync(stoppingToken); + await ProcessAsync(stoppingToken); - return _executingTask; } public override Task StopAsync(CancellationToken cancellationToken) diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index 4f788832..20c3c0b0 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -95,8 +95,7 @@ protected TestFixture() { TestRegistrationServices?.Invoke(services); services.ReplaceSingleton(AddHttpContextAccessorMock); - services.RemoveAll(); - + // services.RemoveAll(); services.AddSingleton(); // Register all ITestDataSeeder implementations dynamically