Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only ignore OperationCanceledException if cancellationToken is cancelled #21250

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions common/Perf/Azure.Sample.Perf/OperationCanceledTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Test.Perf;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Azure.Sample.Perf
{
// The perf framework should ignore OperationCanceledException thrown by Run/RunAsync(), but only
// if the test is being cancelled. This verifies that an OperationCanceledException thrown earlier
// will cause the perf framework to fail fast.
// https://github.com/Azure/azure-sdk-for-net/issues/21241

public class OperationCanceledTest : PerfTest<PerfOptions>
{
public OperationCanceledTest(PerfOptions options) : base(options)
{
}

public override void Run(CancellationToken cancellationToken)
{
throw new OperationCanceledException();
}

public override Task RunAsync(CancellationToken cancellationToken)
{
throw new OperationCanceledException();
}
}
}
17 changes: 14 additions & 3 deletions common/Perf/Azure.Test.Perf/PerfProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,16 @@ private static void RunLoop(IPerfTest test, int index, bool latency, Cancellatio
_lastCompletionTimes[index] = sw.Elapsed;
}
}
catch (OperationCanceledException)
catch (Exception e)
{
if (cancellationToken.IsCancellationRequested && PerfStressUtilities.ContainsOperationCanceledException(e))
{
// If the test has been canceled, ignore if any part of the exception chain is OperationCanceledException.
}
else
{
throw;
}
}
}

Expand Down Expand Up @@ -484,8 +492,11 @@ private static async Task RunLoopAsync(IPerfTest test, int index, bool latency,
}
catch (Exception e)
{
// Ignore if any part of the exception chain is type OperationCanceledException
if (!PerfStressUtilities.ContainsOperationCanceledException(e))
if (cancellationToken.IsCancellationRequested && PerfStressUtilities.ContainsOperationCanceledException(e))
{
// If the test has been canceled, ignore if any part of the exception chain is OperationCanceledException.
}
else
{
throw;
}
Expand Down