throw fewer exceptions during shutdown, and catch exceptions during shutdown in unit test framework

This commit is contained in:
Sebastian Burckhardt 2021-02-18 16:24:51 -08:00
Родитель c6ed600146
Коммит b244e26021
2 изменённых файлов: 38 добавлений и 16 удалений

Просмотреть файл

@ -32,22 +32,31 @@ namespace DurableTask.Netherite
public async ValueTask<T> GetNext(TimeSpan timeout, CancellationToken cancellationToken)
{
T result = default;
bool success = await this.count.WaitAsync((int) timeout.TotalMilliseconds, cancellationToken);
if (success)
try
{
success = this.work.TryDequeue(out result);
// we should always succeed here; but just for the unlikely case that we don't
// (e.g. if concurrent queue implementation is not linearizable),
// put the count back up by one if we didn't actually get an element
if (!success)
{
this.count.Release();
}
}
T result = default;
return result;
bool success = await this.count.WaitAsync((int)timeout.TotalMilliseconds, cancellationToken);
if (success)
{
success = this.work.TryDequeue(out result);
// we should always succeed here; but just for the unlikely case that we don't
// (e.g. if concurrent queue implementation is not linearizable),
// put the count back up by one if we didn't actually get an element
if (!success)
{
this.count.Release();
}
}
return result;
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
return default(T);
}
}
}
}

Просмотреть файл

@ -52,9 +52,22 @@ namespace DurableTask.Netherite.AzureFunctions.Tests
this.AddFunctions(typeof(ClientFunctions));
}
Task IAsyncLifetime.InitializeAsync() => this.functionsHost.StartAsync();
async Task IAsyncLifetime.InitializeAsync()
{
await this.functionsHost.StartAsync();
}
Task IAsyncLifetime.DisposeAsync() => this.functionsHost.StopAsync();
async Task IAsyncLifetime.DisposeAsync()
{
try
{
await this.functionsHost.StopAsync();
}
catch(OperationCanceledException)
{
}
}
protected void AddFunctions(Type functionType) => this.typeLocator.AddFunctionType(functionType);