Skip to content

Commit 9add29c

Browse files
committed
Resolve concurrency with test stub to resolve #49745.
1 parent a0991ea commit 9add29c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/HealthChecks/HealthChecks/test/HealthCheckPublisherHostedServiceTest.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Collections.Concurrent;
56
using System.Collections.Generic;
67
using System.Linq;
78
using System.Threading;
@@ -799,9 +800,17 @@ private class TestPublisher : IHealthCheckPublisher
799800
public TestPublisher()
800801
{
801802
_started = new TaskCompletionSource<object?>(TaskCreationOptions.RunContinuationsAsynchronously);
803+
_entries = new ConcurrentQueue<(HealthReport report, CancellationToken cancellationToken)>();
802804
}
803805

804-
public List<(HealthReport report, CancellationToken cancellationToken)> Entries { get; } = new List<(HealthReport report, CancellationToken cancellationToken)>();
806+
private readonly ConcurrentQueue<(HealthReport report, CancellationToken cancellationToken)> _entries;
807+
public IReadOnlyList<(HealthReport report, CancellationToken cancellationToken)> Entries
808+
{
809+
get
810+
{
811+
return _entries.ToList();
812+
}
813+
}
805814

806815
public Exception? Exception { get; set; }
807816

@@ -811,7 +820,7 @@ public TestPublisher()
811820

812821
public async Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
813822
{
814-
Entries.Add((report, cancellationToken));
823+
_entries.Enqueue((report, cancellationToken));
815824

816825
// Signal that we've started
817826
_started.SetResult(null);

0 commit comments

Comments
 (0)