diff --git a/Src/Compilers/Core/CodeAnalysisTest/AsyncQueueTests.cs b/Src/Compilers/Core/CodeAnalysisTest/AsyncQueueTests.cs new file mode 100644 index 0000000000000000000000000000000000000000..5868c522aa2ee816607e2965789ac59ce0c37740 --- /dev/null +++ b/Src/Compilers/Core/CodeAnalysisTest/AsyncQueueTests.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis.Collections; +using Microsoft.CodeAnalysis.Text; +using Xunit; +using Microsoft.CodeAnalysis.Diagnostics; +using System.Threading; +using System.Threading.Tasks; +using Roslyn.Test.Utilities; + +namespace Microsoft.CodeAnalysis.UnitTests +{ + public class AsyncQueueTests + { + /// + /// Ensure that cancel after completion does not cause an exception to be thrown. + /// + [Fact] + [WorkItem(1097123, "DevDiv")] + public async Task CancelAfterCompleted() + { + var cts = new CancellationTokenSource(); + var queue = new AsyncQueue(cts.Token); + queue.Complete(); + await queue.WhenCompletedAsync.ConfigureAwait(false); + Assert.Equal(TaskStatus.RanToCompletion, queue.WhenCompletedAsync.Status); + cts.Cancel(); + Assert.Equal(TaskStatus.RanToCompletion, queue.WhenCompletedAsync.Status); + } + } +} diff --git a/Src/Compilers/Core/CodeAnalysisTest/CodeAnalysisTest.csproj b/Src/Compilers/Core/CodeAnalysisTest/CodeAnalysisTest.csproj index 011bc0ebd6a7d895a4fdbbdad3a24fc5e8842a36..a6d1b1efce47d4c9b31e394ca4b0210ae2085ef9 100644 --- a/Src/Compilers/Core/CodeAnalysisTest/CodeAnalysisTest.csproj +++ b/Src/Compilers/Core/CodeAnalysisTest/CodeAnalysisTest.csproj @@ -22,6 +22,7 @@ FusionAssemblyIdentity.cs + diff --git a/Src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.TaskCompletionSourceWithCancellation.cs b/Src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.TaskCompletionSourceWithCancellation.cs index 3ef85f4dc9ecdb68611ebe6875b30c8b1688745f..a3e073d10a705aa01e61706f1e524ecbf788c25e 100644 --- a/Src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.TaskCompletionSourceWithCancellation.cs +++ b/Src/Compilers/Core/Portable/DiagnosticAnalyzer/AsyncQueue.TaskCompletionSourceWithCancellation.cs @@ -12,7 +12,7 @@ public sealed partial class AsyncQueue private sealed class TaskCompletionSourceWithCancellation : TaskCompletionSource { private readonly Action OnCancelled = - (tcs) => ((TaskCompletionSourceWithCancellation)tcs).SetCanceled(); + (tcs) => ((TaskCompletionSourceWithCancellation)tcs).TrySetCanceled(); private CancellationTokenRegistration cancellationTokenRegistration;