diff --git a/src/HealthChecks/HealthChecks/test/HealthCheckPublisherHostedServiceTest.cs b/src/HealthChecks/HealthChecks/test/HealthCheckPublisherHostedServiceTest.cs index bfdea1968900..8e8252317afc 100644 --- a/src/HealthChecks/HealthChecks/test/HealthCheckPublisherHostedServiceTest.cs +++ b/src/HealthChecks/HealthChecks/test/HealthCheckPublisherHostedServiceTest.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -799,9 +800,17 @@ private class TestPublisher : IHealthCheckPublisher public TestPublisher() { _started = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _entries = new ConcurrentQueue<(HealthReport report, CancellationToken cancellationToken)>(); } - public List<(HealthReport report, CancellationToken cancellationToken)> Entries { get; } = new List<(HealthReport report, CancellationToken cancellationToken)>(); + private readonly ConcurrentQueue<(HealthReport report, CancellationToken cancellationToken)> _entries; + public IReadOnlyList<(HealthReport report, CancellationToken cancellationToken)> Entries + { + get + { + return _entries.ToList(); + } + } public Exception? Exception { get; set; } @@ -811,7 +820,7 @@ public TestPublisher() public async Task PublishAsync(HealthReport report, CancellationToken cancellationToken) { - Entries.Add((report, cancellationToken)); + _entries.Enqueue((report, cancellationToken)); // Signal that we've started _started.SetResult(null);