- Implemented `MongoIndexModelTests` to verify index models for various stores. - Created `OpenApiMetadataFactory` with methods to generate OpenAPI metadata. - Added tests for `OpenApiMetadataFactory` to ensure expected defaults and URL overrides. - Introduced `ObserverSurfaceSecrets` and `WebhookSurfaceSecrets` for managing secrets. - Developed `RuntimeSurfaceFsClient` and `WebhookSurfaceFsClient` for manifest retrieval. - Added dependency injection tests for `SurfaceEnvironmentRegistration` in both Observer and Webhook contexts. - Implemented tests for secret resolution in `ObserverSurfaceSecretsTests` and `WebhookSurfaceSecretsTests`. - Created `EnsureLinkNotMergeCollectionsMigrationTests` to validate MongoDB migration logic. - Added project files for MongoDB tests and NuGet package mirroring.
37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
namespace LedgerReplayHarness;
|
|
|
|
internal sealed class TaskThrottler
|
|
{
|
|
private readonly SemaphoreSlim _semaphore;
|
|
private readonly List<Task> _tasks = new();
|
|
|
|
public TaskThrottler(int maxDegreeOfParallelism)
|
|
{
|
|
_semaphore = new SemaphoreSlim(maxDegreeOfParallelism > 0 ? maxDegreeOfParallelism : 1);
|
|
}
|
|
|
|
public async Task RunAsync(Func<Task> taskFactory, CancellationToken cancellationToken)
|
|
{
|
|
await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
var task = Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
await taskFactory().ConfigureAwait(false);
|
|
}
|
|
finally
|
|
{
|
|
_semaphore.Release();
|
|
}
|
|
}, cancellationToken);
|
|
lock (_tasks) _tasks.Add(task);
|
|
}
|
|
|
|
public async Task DrainAsync(CancellationToken cancellationToken)
|
|
{
|
|
Task[] pending;
|
|
lock (_tasks) pending = _tasks.ToArray();
|
|
await Task.WhenAll(pending).WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|