From 945730fddac0265780040bd1bf89d1839f8525b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 24 Jan 2025 12:18:58 +0100 Subject: [PATCH] fix: MongoCollectionProvider.Check had a condition wrong --- Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs | 7 ++++--- Common/tests/Pollster/PollsterTest.cs | 5 ++--- Utils/src/HealthCheckResultCombiner.cs | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs index 9b810fed1..09611d13a 100644 --- a/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs +++ b/Adaptors/MongoDB/src/Common/MongoCollectionProvider.cs @@ -16,6 +16,7 @@ // along with this program. If not, see . using System; +using System.Data; using System.Threading; using System.Threading.Tasks; @@ -68,10 +69,10 @@ public Task Check(HealthCheckTag tag) HealthCheckTag.Startup or HealthCheckTag.Readiness => Task.FromResult(isInitialized_ ? HealthCheckResult.Healthy() : HealthCheckResult - .Unhealthy($"Mongo Collection<{nameof(TData)}> not initialized yet.")), - HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is null + .Unhealthy($"Mongo Collection<{typeof(TData)}> not initialized yet.")), + HealthCheckTag.Liveness => Task.FromResult(isInitialized_ && mongoCollection_ is not null ? HealthCheckResult.Healthy() - : HealthCheckResult.Unhealthy($"Mongo Collection<{nameof(TData)}> not initialized yet.")), + : HealthCheckResult.Unhealthy($"Mongo Collection<{typeof(TData)}> not initialized yet.")), _ => throw new ArgumentOutOfRangeException(nameof(tag), tag, null), diff --git a/Common/tests/Pollster/PollsterTest.cs b/Common/tests/Pollster/PollsterTest.cs index 9eed80416..21814ebed 100644 --- a/Common/tests/Pollster/PollsterTest.cs +++ b/Common/tests/Pollster/PollsterTest.cs @@ -356,9 +356,8 @@ await testServiceProvider.Pollster.Init(CancellationToken.None) Console.WriteLine(res.Description); - Assert.AreEqual(new StringBuilder().AppendLine(desc) - .ToString(), - healthResult.Description); + Assert.AreEqual(desc, + healthResult.Description?.Trim()); Assert.AreEqual(new AggregateException(ex).Message, healthResult.Exception?.Message); Assert.AreEqual(HealthStatus.Unhealthy, diff --git a/Utils/src/HealthCheckResultCombiner.cs b/Utils/src/HealthCheckResultCombiner.cs index 3a457eaf4..cd4bbfb7d 100644 --- a/Utils/src/HealthCheckResultCombiner.cs +++ b/Utils/src/HealthCheckResultCombiner.cs @@ -49,8 +49,9 @@ public static async Task Combine(HealthCheckTag { var exceptions = new List(); var data = new Dictionary(); - var description = new StringBuilder(desc); + var description = new StringBuilder(); var worstStatus = HealthStatus.Healthy; + description.AppendLine(desc); foreach (var healthCheckResult in await providers.Select(p => p.Check(tag)) .WhenAll()