Change TaskCanceledException to OperationCancelledException.
authorLakshmi Priya Sekar <lasekar@microsoft.com>
Fri, 3 Nov 2017 00:48:57 +0000 (17:48 -0700)
committerLakshmi Priya Sekar <lasekar@microsoft.com>
Fri, 3 Nov 2017 00:49:49 +0000 (17:49 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/cbc0b590e402f9ff95a752c5d5d170faebb9c8d4

src/libraries/System.Net.Security/src/System/Net/Security/SslState.cs
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamAlpnTests.cs

index 86adf7a..33e8f5a 100644 (file)
@@ -642,7 +642,7 @@ namespace System.Net.Security
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
                 // Cancel async operation, before I/O starts.
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
@@ -752,8 +752,8 @@ namespace System.Net.Security
         {
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
-                // Return async operation if cancellation requested.
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                // Cancel async operation if cancellation requested.
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
@@ -813,8 +813,8 @@ namespace System.Net.Security
         {
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
-                // Return async operation if cancellation requested.
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                // Cancel async operation if cancellation requested.
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
@@ -849,7 +849,7 @@ namespace System.Net.Security
         {
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
@@ -895,7 +895,7 @@ namespace System.Net.Security
         {
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
@@ -953,7 +953,7 @@ namespace System.Net.Security
         {
             if (asyncRequest != null && asyncRequest.CancellationToken.IsCancellationRequested)
             {
-                asyncRequest.CompleteUserWithError(new TaskCanceledException());
+                asyncRequest.CompleteUserWithError(new OperationCanceledException(asyncRequest.CancellationToken));
                 return;
             }
 
index d2a9c4e..1e8a669 100644 (file)
@@ -79,7 +79,7 @@ namespace System.Net.Security.Tests
                 serverOptions.RemoteCertificateValidationCallback = AllowAnyServerCertificate;
 
                 CancellationTokenSource cts = new CancellationTokenSource();
-                Task clientTask = Assert.ThrowsAsync<TaskCanceledException>(() => client.AuthenticateAsClientAsync(clientOptions, cts.Token));
+                Task clientTask = Assert.ThrowsAnyAsync<OperationCanceledException>(() => client.AuthenticateAsClientAsync(clientOptions, cts.Token));
                 Task serverTask = Assert.ThrowsAsync<TimeoutException>(() => server.AuthenticateAsServerAsync(serverOptions, CancellationToken.None));
 
                 cts.Cancel();
@@ -107,7 +107,7 @@ namespace System.Net.Security.Tests
 
                 CancellationTokenSource cts = new CancellationTokenSource();
                 Task clientTask = Assert.ThrowsAsync<TimeoutException>(() => client.AuthenticateAsClientAsync(clientOptions, CancellationToken.None));
-                Task serverTask = Assert.ThrowsAsync<TaskCanceledException>(() => server.AuthenticateAsServerAsync(serverOptions, cts.Token));
+                Task serverTask = Assert.ThrowsAnyAsync<OperationCanceledException>(() => server.AuthenticateAsServerAsync(serverOptions, cts.Token));
 
                 cts.Cancel();
                 Assert.True(Task.WaitAll(new[] { clientTask, serverTask }, TestConfiguration.PassingTestTimeoutMilliseconds));