From b64c0105b80b8130c48a628d540f4616845941c8 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Fri, 11 May 2018 14:57:20 -0700 Subject: [PATCH] Use correct TaskCompletionSource ctor (#2567) --- test/Kestrel.FunctionalTests/HttpsTests.cs | 4 ++-- test/Kestrel.FunctionalTests/RequestTests.cs | 14 ++++++-------- test/Kestrel.FunctionalTests/ResponseTests.cs | 16 ++++++---------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/test/Kestrel.FunctionalTests/HttpsTests.cs b/test/Kestrel.FunctionalTests/HttpsTests.cs index e113baab82..30ae3470ed 100644 --- a/test/Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsTests.cs @@ -441,13 +441,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { public LogLevel LastLogLevel { get; set; } public EventId LastEventId { get; set; } - public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(); + public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { LastLogLevel = logLevel; LastEventId = eventId; - Task.Run(() => LogTcs.SetResult(null)); + LogTcs.SetResult(null); } public bool IsEnabled(LogLevel logLevel) diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index c98a62da09..c57c5af39d 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1217,10 +1217,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int connectionFinSentEventId = 7; const int maxRequestBufferSize = 4096; - var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var serverClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var appFuncCompleted = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockLogger = new Mock(); mockLogger @@ -1276,9 +1276,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests await serverClosedConnection.Task; - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => appFuncCompleted.SetResult(null)); + appFuncCompleted.SetResult(null); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -1308,7 +1306,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests [MemberData(nameof(ConnectionAdapterData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { - var readTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var testContext = new TestServiceContext() diff --git a/test/Kestrel.FunctionalTests/ResponseTests.cs b/test/Kestrel.FunctionalTests/ResponseTests.cs index 12d430eb38..f98fa41185 100644 --- a/test/Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Kestrel.FunctionalTests/ResponseTests.cs @@ -2337,9 +2337,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int maxRequestBufferSize = 4096; var requestAborted = false; - var readCallbackUnwired = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var clientClosedConnection = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var mockLogger = new Mock(); @@ -2402,9 +2402,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } catch (Exception ex) { - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => writeTcs.SetException(ex)); + writeTcs.SetException(ex); throw; } @@ -2444,7 +2442,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests const int responseBodySize = responseBodySegmentSize * responseBodySegmentCount; var requestAborted = false; - var appCompletedTcs = new TaskCompletionSource(TaskContinuationOptions.RunContinuationsAsynchronously); + var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(Logger) { CallBase = true }; var testContext = new TestServiceContext() @@ -2475,9 +2473,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { // WriteAsync shouldn't throw without a CancellationToken passed in. Unfortunately a ECONNRESET UvException sometimes gets thrown. // This will be fixed by https://github.com/aspnet/KestrelHttpServer/pull/2547 - // TaskContinuationOptions.RunContinuationsAsynchronously sometimes runs inline anyway in - // situations such as this where the awaiter starts awaiting right when SetResult is called. - _ = Task.Run(() => appCompletedTcs.SetResult(null)); + appCompletedTcs.SetResult(null); } }, testContext, listenOptions)) {