diff --git a/eng/helix/content/RunTests/ProcessUtil.cs b/eng/helix/content/RunTests/ProcessUtil.cs index 98a62c9a4bcd..2cd13c856d79 100644 --- a/eng/helix/content/RunTests/ProcessUtil.cs +++ b/eng/helix/content/RunTests/ProcessUtil.cs @@ -66,7 +66,7 @@ public static async Task RunAsync( string filename, string arguments, string? workingDirectory = null, - string dumpDirectoryPath = null, + string? dumpDirectoryPath = null, bool throwOnError = true, IDictionary? environmentVariables = null, Action? outputDataReceived = null, diff --git a/src/Hosting/Hosting/src/WebHostExtensions.cs b/src/Hosting/Hosting/src/WebHostExtensions.cs index 0b594be84f84..b1b317272bc9 100644 --- a/src/Hosting/Hosting/src/WebHostExtensions.cs +++ b/src/Hosting/Hosting/src/WebHostExtensions.cs @@ -157,11 +157,11 @@ private static async Task WaitForTokenShutdownAsync(this IWebHost host, Cancella }, applicationLifetime); - var waitForStop = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var waitForStop = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); applicationLifetime.ApplicationStopping.Register(obj => { - var tcs = (TaskCompletionSource)obj; - tcs.TrySetResult(null); + var tcs = (TaskCompletionSource)obj; + tcs.TrySetResult(); }, waitForStop); await waitForStop.Task; diff --git a/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs b/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs index e6e724c98c40..50759ff41f1e 100644 --- a/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs +++ b/src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs @@ -140,7 +140,7 @@ public override async Task DeployAsync() AddEnvironmentVariablesToProcess(startInfo, DeploymentParameters.EnvironmentVariables); Uri actualUrl = null; - var started = new TaskCompletionSource(); + var started = new TaskCompletionSource(); HostProcess = new Process() { StartInfo = startInfo }; HostProcess.EnableRaisingEvents = true; @@ -148,7 +148,7 @@ public override async Task DeployAsync() { if (string.Equals(dataArgs.Data, ApplicationStartedMessage)) { - started.TrySetResult(null); + started.TrySetResult(); } else if (!string.IsNullOrEmpty(dataArgs.Data)) { diff --git a/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs b/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs index 2cf50a6352cf..78324eab9e80 100644 --- a/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs +++ b/src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs @@ -17,7 +17,7 @@ internal class ConnectionDispatcher where T : BaseConnectionContext private readonly ServiceContext _serviceContext; private readonly Func _connectionDelegate; private readonly TransportConnectionManager _transportConnectionManager; - private readonly TaskCompletionSource _acceptLoopTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _acceptLoopTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); public ConnectionDispatcher(ServiceContext serviceContext, Func connectionDelegate, TransportConnectionManager transportConnectionManager) { @@ -73,7 +73,7 @@ async Task AcceptConnectionsAsync() } finally { - _acceptLoopTcs.TrySetResult(null); + _acceptLoopTcs.TrySetResult(); } } } diff --git a/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs b/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs index 292d2c499d6c..c4004372bfc9 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs @@ -46,11 +46,11 @@ internal abstract class Http3Stream : HttpProtocol, IHttpHeadersHandler, IThread private readonly Http3Connection _http3Connection; private bool _receivedHeaders; - private TaskCompletionSource _appCompleted; + private TaskCompletionSource _appCompleted; public Pipe RequestBodyPipe { get; } - public Http3Stream(Http3Connection http3Connection, Http3StreamContext context) + public Http3Stream(Http3Connection http3Connection, Http3StreamContext context) { Initialize(context); @@ -307,7 +307,7 @@ protected override void OnRequestProcessingEnded() { Debug.Assert(_appCompleted != null); - _appCompleted.SetResult(new object()); + _appCompleted.SetResult(); } private bool TryClose() @@ -457,7 +457,7 @@ private Task ProcessHeadersFrameAsync(IHttpApplication appli _receivedHeaders = true; InputRemaining = HttpRequestHeaders.ContentLength; - _appCompleted = new TaskCompletionSource(); + _appCompleted = new TaskCompletionSource(); ThreadPool.UnsafeQueueUserWorkItem(this, preferLocal: false); diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs index c81dce45673c..c019c27de563 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnection.cs @@ -20,7 +20,7 @@ internal abstract class KestrelConnection : IConnectionHeartbeatFeature, IConnec private bool _completed; private readonly CancellationTokenSource _connectionClosingCts = new CancellationTokenSource(); - private readonly TaskCompletionSource _completionTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _completionTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); protected readonly long _id; protected readonly ServiceContext _serviceContext; protected readonly TransportConnectionManager _transportConnectionManager; @@ -166,7 +166,7 @@ public void RequestClose() public void Complete() { - _completionTcs.TrySetResult(null); + _completionTcs.TrySetResult(); _connectionClosingCts.Dispose(); } diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/TransportConnectionManager.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/TransportConnectionManager.cs index 0021bc5b0cc4..444d2e1d48d5 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/TransportConnectionManager.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/TransportConnectionManager.cs @@ -95,8 +95,8 @@ private static Task CancellationTokenAsTask(CancellationToken token) return Task.CompletedTask; } - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - token.Register(() => tcs.SetResult(null)); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + token.Register(() => tcs.SetResult()); return tcs.Task; } } diff --git a/src/Servers/Kestrel/Core/src/KestrelServer.cs b/src/Servers/Kestrel/Core/src/KestrelServer.cs index 8359b9b4baea..16d9e34f0131 100644 --- a/src/Servers/Kestrel/Core/src/KestrelServer.cs +++ b/src/Servers/Kestrel/Core/src/KestrelServer.cs @@ -31,7 +31,7 @@ public class KestrelServer : IServer private bool _hasStarted; private int _stopping; private readonly CancellationTokenSource _stopCts = new CancellationTokenSource(); - private readonly TaskCompletionSource _stoppedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _stoppedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private IDisposable _configChangedRegistration; @@ -238,7 +238,7 @@ public async Task StopAsync(CancellationToken cancellationToken) _bindSemaphore.Release(); } - _stoppedTcs.TrySetResult(null); + _stoppedTcs.TrySetResult(); } // Ungraceful shutdown diff --git a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs index 645f0538f95f..246795b355e6 100644 --- a/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs +++ b/src/Servers/Kestrel/Core/test/ConcurrentPipeWriterTests.cs @@ -121,7 +121,7 @@ public async Task QueuesIfFlushIsNotAwaited() Assert.False(flushTask0.IsCompleted); Assert.False(flushTask1.IsCompleted); - mockPipeWriter.FlushTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + mockPipeWriter.FlushTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); pipeWriterFlushTcsArray[0].SetResult(default); await mockPipeWriter.FlushTcs.Task.DefaultTimeout(); @@ -141,7 +141,7 @@ public async Task QueuesIfFlushIsNotAwaited() Assert.False(flushTask0.IsCompleted); Assert.False(flushTask1.IsCompleted); - mockPipeWriter.FlushTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + mockPipeWriter.FlushTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); pipeWriterFlushTcsArray[1].SetResult(default); await mockPipeWriter.FlushTcs.Task.DefaultTimeout(); @@ -235,7 +235,7 @@ public async Task KeepsQueueIfInnerFlushFinishesBetweenGetMemoryAndAdvance() Assert.Equal(3, mockPipeWriter.AdvanceCallCount); Assert.Equal(2, mockPipeWriter.FlushCallCount); Assert.False(flushTask1.IsCompleted); - + pipeWriterFlushTcsArray[1].SetResult(default); await flushTask1.DefaultTimeout(); @@ -426,14 +426,14 @@ public MockPipeWriter(TaskCompletionSource[] flushResults) public int FlushCallCount { get; set; } public int CancelPendingFlushCallCount { get; set; } - public TaskCompletionSource FlushTcs { get; set; } + public TaskCompletionSource FlushTcs { get; set; } public Exception CompleteException { get; set; } public override ValueTask FlushAsync(CancellationToken cancellationToken = default) { FlushCallCount++; - FlushTcs?.TrySetResult(null); + FlushTcs?.TrySetResult(); return new ValueTask(_flushResults[FlushCallCount - 1].Task); } diff --git a/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs b/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs index fc426a210f51..8c126e2b2ae5 100644 --- a/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs +++ b/src/Servers/Kestrel/Core/test/ConnectionDispatcherTests.cs @@ -25,7 +25,7 @@ public async Task OnConnectionCreatesLogScopeWithConnectionId() { var serviceContext = new TestServiceContext(); // This needs to run inline - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var connection = new Mock { CallBase = true }.Object; connection.ConnectionClosed = new CancellationToken(canceled: true); @@ -47,7 +47,7 @@ public async Task OnConnectionCreatesLogScopeWithConnectionId() Assert.True(pairs.ContainsKey("ConnectionId")); Assert.Equal(connection.ConnectionId, pairs["ConnectionId"]); - tcs.TrySetResult(null); + tcs.TrySetResult(); await task; diff --git a/src/Servers/Kestrel/Core/test/HeartbeatTests.cs b/src/Servers/Kestrel/Core/test/HeartbeatTests.cs index 680fa6af8b64..1af0a541a49d 100644 --- a/src/Servers/Kestrel/Core/test/HeartbeatTests.cs +++ b/src/Servers/Kestrel/Core/test/HeartbeatTests.cs @@ -29,12 +29,12 @@ public async Task HeartbeatTakingLongerThanIntervalIsLoggedAsError() var debugger = new Mock(); var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); - var handlerStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var handlerStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var now = systemClock.UtcNow; heartbeatHandler.Setup(h => h.OnHeartbeat(now)).Callback(() => { - handlerStartedTcs.SetResult(null); + handlerStartedTcs.SetResult(); handlerMre.Wait(); }); debugger.Setup(d => d.IsAttached).Returns(false); @@ -67,12 +67,12 @@ public async Task HeartbeatTakingLongerThanIntervalIsNotLoggedAsErrorIfDebuggerA var debugger = new Mock(); var kestrelTrace = new Mock(); var handlerMre = new ManualResetEventSlim(); - var handlerStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var handlerStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var now = systemClock.UtcNow; heartbeatHandler.Setup(h => h.OnHeartbeat(now)).Callback(() => { - handlerStartedTcs.SetResult(null); + handlerStartedTcs.SetResult(); handlerMre.Wait(); }); diff --git a/src/Servers/Kestrel/Core/test/HttpConnectionTests.cs b/src/Servers/Kestrel/Core/test/HttpConnectionTests.cs index 476be4ffdadf..a8781e761e68 100644 --- a/src/Servers/Kestrel/Core/test/HttpConnectionTests.cs +++ b/src/Servers/Kestrel/Core/test/HttpConnectionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO.Pipelines; @@ -29,14 +29,14 @@ public async Task WriteDataRateTimeoutAbortsConnection() var httpConnection = new HttpConnection(httpConnectionContext); - var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var http1Connection = new Http1Connection(httpConnectionContext); httpConnection.Initialize(http1Connection); http1Connection.Reset(); http1Connection.RequestAborted.Register(() => { - aborted.SetResult(null); + aborted.SetResult(); }); httpConnection.OnTimeout(TimeoutReason.WriteDataRate); diff --git a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs index f7dcef5b3866..4f41ddbe1900 100644 --- a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs +++ b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs @@ -373,7 +373,7 @@ public async Task StopAsyncDispatchesSubsequentStopAsyncContinuations() } }; - var unbindTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var unbindTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockTransport = new Mock(); var mockTransportFactory = new Mock(); @@ -411,7 +411,7 @@ public async Task StopAsyncDispatchesSubsequentStopAsyncContinuations() stopTask1.Wait(); }); - unbindTcs.SetResult(null); + unbindTcs.SetResult(); // If stopTask2 is completed inline by the first call to StopAsync, stopTask1 will never complete. await stopTask1.DefaultTimeout(); @@ -467,16 +467,16 @@ public async Task ReloadsOnConfigurationChangeWhenOptedIn() }).Build(); Func changeCallback = null; - TaskCompletionSource changeCallbackRegisteredTcs = null; + TaskCompletionSource changeCallbackRegisteredTcs = null; var mockChangeToken = new Mock(); mockChangeToken.Setup(t => t.RegisterChangeCallback(It.IsAny>(), It.IsAny())).Returns, object>((callback, state) => { - changeCallbackRegisteredTcs?.SetResult(null); + changeCallbackRegisteredTcs?.SetResult(); changeCallback = () => { - changeCallbackRegisteredTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + changeCallbackRegisteredTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); callback(state); return changeCallbackRegisteredTcs.Task; }; diff --git a/src/Servers/Kestrel/Core/test/MessageBodyTests.cs b/src/Servers/Kestrel/Core/test/MessageBodyTests.cs index 5ea87c1b6cf7..ff1280a3f4dc 100644 --- a/src/Servers/Kestrel/Core/test/MessageBodyTests.cs +++ b/src/Servers/Kestrel/Core/test/MessageBodyTests.cs @@ -859,11 +859,11 @@ public async Task LogsWhenStopsReadingRequestBody() { using (var input = new TestInput()) { - var logEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var logEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockLogger = new Mock(); mockLogger .Setup(logger => logger.RequestBodyDone("ConnectionId", "RequestId")) - .Callback(() => logEvent.SetResult(null)); + .Callback(() => logEvent.SetResult()); mockLogger .Setup(logger => logger.IsEnabled(Extensions.Logging.LogLevel.Debug)) .Returns(true); diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs index 56aa728e7e08..d07281a32960 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvConnection.cs @@ -31,7 +31,7 @@ internal partial class LibuvConnection : TransportConnection private MemoryHandle _bufferHandle; private Task _processingTask; - private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private bool _connectionClosed; public LibuvConnection(UvStreamHandle socket, @@ -253,7 +253,7 @@ private void FireConnectionClosed() { state.CancelConnectionClosedToken(); - state._waitForConnectionClosedTcs.TrySetResult(null); + state._waitForConnectionClosedTcs.TrySetResult(); }, this, preferLocal: false); diff --git a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs index 31f5049373bb..84ef7168cb90 100644 --- a/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs +++ b/src/Servers/Kestrel/Transport.Libuv/src/Internal/LibuvThread.cs @@ -25,7 +25,7 @@ internal class LibuvThread : PipeScheduler private readonly LibuvFunctions _libuv; private readonly IHostApplicationLifetime _appLifetime; private readonly Thread _thread; - private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _threadTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private readonly UvLoopHandle _loop; private readonly UvAsyncHandle _post; private Queue _workAdding = new Queue(1024); @@ -224,7 +224,7 @@ public Task PostAsync(Action callback, T state) return Task.CompletedTask; } - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var work = new Work { CallbackAdapter = CallbackAdapter.PostAsyncCallbackAdapter, @@ -344,7 +344,7 @@ private void ThreadStart(object parameter) _closeError = _closeError == null ? ex : new AggregateException(_closeError, ex); } WriteReqPool.Dispose(); - _threadTcs.SetResult(null); + _threadTcs.SetResult(); #if DEBUG && !INNER_LOOP // Check for handle leaks after disposing everything @@ -383,7 +383,7 @@ private bool DoPostWork() try { work.CallbackAdapter(work.Callback, work.State); - work.Completion?.TrySetResult(null); + work.Completion?.TrySetResult(); } catch (Exception ex) { @@ -446,7 +446,7 @@ private struct Work public Action CallbackAdapter; public object Callback; public object State; - public TaskCompletionSource Completion; + public TaskCompletionSource Completion; } private struct CloseHandle diff --git a/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs b/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs index b3ed1b94fe07..934195fa3fb2 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/ListenerPrimaryTests.cs @@ -123,7 +123,7 @@ public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() } // Create a pipe connection and keep it open without sending any data - var connectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionTrace = new LibuvTrace(new TestApplicationErrorLogger()); var pipe = new UvPipeHandle(connectionTrace); @@ -147,7 +147,7 @@ public async Task NonListenerPipeConnectionsAreLoggedAndIgnored() } else { - connectTcs.SetResult(null); + connectTcs.SetResult(); } }, null); diff --git a/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs index 66e120b69242..f4828473486f 100644 --- a/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs +++ b/src/Servers/Kestrel/Transport.Libuv/test/TestHelpers/MockLibuv.cs @@ -14,7 +14,7 @@ internal class MockLibuv : LibuvFunctions private uv_async_cb _onPost; private readonly object _postLock = new object(); - private TaskCompletionSource _onPostTcs = new TaskCompletionSource(); + private TaskCompletionSource _onPostTcs = new TaskCompletionSource(); private bool _completedOnPostTcs; private bool _stopLoop; @@ -41,7 +41,7 @@ unsafe public MockLibuv() { if (_completedOnPostTcs) { - _onPostTcs = new TaskCompletionSource(); + _onPostTcs = new TaskCompletionSource(); _completedOnPostTcs = false; } @@ -89,7 +89,7 @@ unsafe public MockLibuv() // when the code attempts to call uv_async_send after awaiting // OnPostTask. Task.Run so the run loop doesn't block either. var onPostTcs = _onPostTcs; - Task.Run(() => onPostTcs.TrySetResult(null)); + Task.Run(() => onPostTcs.TrySetResult()); } } } diff --git a/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs b/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs index 8a17ae6aa531..85880cebca15 100644 --- a/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs +++ b/src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs @@ -25,7 +25,7 @@ internal class QuicStreamContext : TransportConnection, IStreamDirectionFeature, private string _connectionId; private const int MinAllocBufferSize = 4096; private volatile Exception _shutdownReason; - private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private readonly object _shutdownLock = new object(); public QuicStreamContext(QuicStream stream, QuicConnectionContext connection, QuicTransportContext context) @@ -200,7 +200,7 @@ private void FireStreamClosed() { state.CancelConnectionClosedToken(); - state._waitForConnectionClosedTcs.TrySetResult(null); + state._waitForConnectionClosedTcs.TrySetResult(); }, this, preferLocal: false); diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs index 4088dab97871..d8f6146d37e5 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs @@ -31,7 +31,7 @@ internal sealed class SocketConnection : TransportConnection private volatile bool _socketDisposed; private volatile Exception _shutdownReason; private Task _processingTask; - private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _waitForConnectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private bool _connectionClosed; private readonly bool _waitForData; @@ -317,7 +317,7 @@ private void FireConnectionClosed() { state.CancelConnectionClosedToken(); - state._waitForConnectionClosedTcs.TrySetResult(null); + state._waitForConnectionClosedTcs.TrySetResult(); }, this, preferLocal: false); diff --git a/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs b/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs index 4e390b3508b0..d5788e336912 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/Http2/ShutdownTests.cs @@ -47,16 +47,16 @@ public ShutdownTests() [SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/9985", Queues = "Fedora.28.Amd64;Fedora.28.Amd64.Open")] public async Task GracefulShutdownWaitsForRequestsToFinish() { - var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestUnblocked = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestStopping = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestUnblocked = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStopping = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(TestApplicationErrorLogger) { CallBase = true }; mockKestrelTrace .Setup(m => m.Http2ConnectionClosing(It.IsAny())) - .Callback(() => requestStopping.SetResult(null)); + .Callback(() => requestStopping.SetResult()); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object); @@ -64,7 +64,7 @@ public async Task GracefulShutdownWaitsForRequestsToFinish() using (var server = new TestServer(async context => { - requestStarted.SetResult(null); + requestStarted.SetResult(); await requestUnblocked.Task.DefaultTimeout(); await context.Response.WriteAsync("hello world " + context.Request.Protocol); }, @@ -88,7 +88,7 @@ public async Task GracefulShutdownWaitsForRequestsToFinish() await requestStopping.Task.DefaultTimeout(); // Unblock the request - requestUnblocked.SetResult(null); + requestUnblocked.SetResult(); Assert.Equal("hello world HTTP/2", await requestTask); await stopTask.DefaultTimeout(); @@ -103,8 +103,8 @@ public async Task GracefulShutdownWaitsForRequestsToFinish() [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/21521")] // Test still quarantined due to Sockets.Functional tests. public async Task GracefulTurnsAbortiveIfRequestsDoNotFinish() { - var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestUnblocked = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestUnblocked = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var memoryPoolFactory = new DiagnosticMemoryPoolFactory(allowLateReturn: true); @@ -118,7 +118,7 @@ public async Task GracefulTurnsAbortiveIfRequestsDoNotFinish() // Abortive shutdown leaves one request hanging using (var server = new TestServer(async context => { - requestStarted.SetResult(null); + requestStarted.SetResult(); await requestUnblocked.Task.DefaultTimeout(); await context.Response.WriteAsync("hello world " + context.Request.Protocol); }, @@ -154,7 +154,7 @@ public async Task GracefulTurnsAbortiveIfRequestsDoNotFinish() Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Message.Contains("Some connections failed to close gracefully during server shutdown.")); Assert.DoesNotContain(TestApplicationErrorLogger.Messages, m => m.Message.Contains("Request finished in")); - requestUnblocked.SetResult(null); + requestUnblocked.SetResult(); await memoryPoolFactory.WhenAllBlocksReturned(TestConstants.DefaultTimeout); } diff --git a/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs b/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs index 252c091afbcb..430e7fbfd012 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/MaxRequestBufferSizeTests.cs @@ -118,8 +118,8 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); var maxSendSize = 4096; - var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var lastBytesWritten = DateTime.MaxValue; var memoryPoolFactory = new DiagnosticMemoryPoolFactory(allowLateReturn: true); @@ -145,7 +145,7 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter } Assert.Equal(data.Length, bytesWritten); - clientFinishedSendingRequestBody.TrySetResult(null); + clientFinishedSendingRequestBody.TrySetResult(); }; var sendTask = sendFunc(); @@ -180,7 +180,7 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter Assert.InRange(bytesWritten, minimumExpectedBytesWritten, maximumExpectedBytesWritten); // Tell server to start reading request body - startReadingRequestBody.TrySetResult(null); + startReadingRequestBody.TrySetResult(); // Wait for sendTask to finish sending the remaining bytes await sendTask; @@ -191,7 +191,7 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter await sendTask; // Tell server to start reading request body - startReadingRequestBody.TrySetResult(null); + startReadingRequestBody.TrySetResult(); } await AssertStreamContains(stream, $"bytesRead: {data.Length}"); @@ -211,8 +211,8 @@ public async Task ServerShutsDownGracefullyWhenMaxRequestBufferSizeExceeded() var bytesWrittenPollingInterval = TimeSpan.FromMilliseconds(bytesWrittenTimeout.TotalMilliseconds / 10); var maxSendSize = 4096; - var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var startReadingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientFinishedSendingRequestBody = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var lastBytesWritten = DateTime.MaxValue; var memoryPoolFactory = new DiagnosticMemoryPoolFactory(allowLateReturn: true); @@ -237,7 +237,7 @@ public async Task ServerShutsDownGracefullyWhenMaxRequestBufferSizeExceeded() lastBytesWritten = DateTime.Now; } - clientFinishedSendingRequestBody.TrySetResult(null); + clientFinishedSendingRequestBody.TrySetResult(); }; var ignore = sendFunc(); @@ -276,16 +276,16 @@ public async Task ServerShutsDownGracefullyWhenMaxRequestBufferSizeExceeded() } } // Allow appfunc to unblock - startReadingRequestBody.SetResult(null); - clientFinishedSendingRequestBody.SetResult(null); + startReadingRequestBody.SetResult(); + clientFinishedSendingRequestBody.SetResult(); await memoryPoolFactory.WhenAllBlocksReturned(TestConstants.DefaultTimeout); } private async Task StartWebHost(long? maxRequestBufferSize, byte[] expectedBody, bool useConnectionAdapter, - TaskCompletionSource startReadingRequestBody, - TaskCompletionSource clientFinishedSendingRequestBody, + TaskCompletionSource startReadingRequestBody, + TaskCompletionSource clientFinishedSendingRequestBody, Func> memoryPoolFactory = null) { var host = TransportSelector.GetWebHostBuilder(memoryPoolFactory, maxRequestBufferSize) diff --git a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs index 9659aa19a338..ab4ce8485e12 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/RequestTests.cs @@ -171,7 +171,7 @@ public async Task DoesNotHangOnConnectionCloseRequest() public async Task CanHandleMultipleConcurrentRequests() { var requestNumber = 0; - var ensureConcurrentRequestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var ensureConcurrentRequestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async context => { @@ -181,7 +181,7 @@ public async Task CanHandleMultipleConcurrentRequests() } else { - ensureConcurrentRequestTcs.SetResult(null); + ensureConcurrentRequestTcs.SetResult(); } }, new TestServiceContext(LoggerFactory))) { @@ -504,15 +504,15 @@ public async Task AbortingTheConnectionSendsFIN() public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { - appStartedTcs.SetResult(null); + appStartedTcs.SetResult(); var connectionLifetimeFeature = context.Features.Get(); - connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult()); return Task.CompletedTask; }, testContext, listenOptions)) @@ -540,12 +540,12 @@ await connection.Send( public async Task ConnectionClosedTokenFiresOnServerFIN(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { var connectionLifetimeFeature = context.Features.Get(); - connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult()); return Task.CompletedTask; }, testContext, listenOptions)) @@ -577,12 +577,12 @@ await connection.ReceiveEnd($"HTTP/1.1 200 OK", public async Task ConnectionClosedTokenFiresOnServerAbort(ListenOptions listenOptions) { var testContext = new TestServiceContext(LoggerFactory); - var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(context => { var connectionLifetimeFeature = context.Features.Get(); - connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult(null)); + connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult()); context.Abort(); @@ -623,7 +623,7 @@ public async Task RequestsCanBeAbortedMidRead(ListenOptions listenOptions) var testContext = new TestServiceContext(LoggerFactory); - var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var registrationTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var requestId = 0; @@ -713,10 +713,10 @@ public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions lis const int connectionFinSentEventId = 7; const int maxRequestBufferSize = 4096; - 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 readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); TestSink.MessageLogged += context => { @@ -728,11 +728,11 @@ public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions lis if (context.EventId.Id == connectionPausedEventId) { - readCallbackUnwired.TrySetResult(null); + readCallbackUnwired.TrySetResult(); } else if (context.EventId == connectionFinSentEventId) { - serverClosedConnection.SetResult(null); + serverClosedConnection.SetResult(); } }; @@ -760,7 +760,7 @@ public async Task ServerCanAbortConnectionAfterUnobservedClose(ListenOptions lis await serverClosedConnection.Task; - appFuncCompleted.SetResult(null); + appFuncCompleted.SetResult(); }, testContext, listenOptions)) { using (var connection = server.CreateConnection()) @@ -778,7 +778,7 @@ await connection.Send( await readCallbackUnwired.Task.DefaultTimeout(); } - clientClosedConnection.SetResult(null); + clientClosedConnection.SetResult(); await appFuncCompleted.Task.DefaultTimeout(); await server.StopAsync(); @@ -791,8 +791,8 @@ await connection.Send( [MemberData(nameof(ConnectionMiddlewareData))] public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions listenOptions) { - var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object); @@ -801,7 +801,7 @@ public async Task AppCanHandleClientAbortingConnectionMidRequest(ListenOptions l using (var server = new TestServer(async context => { - appStartedTcs.SetResult(null); + appStartedTcs.SetResult(); try { diff --git a/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs b/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs index 85b4f8a51cb4..4e6194514337 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/ResponseTests.cs @@ -139,19 +139,19 @@ public async Task IgnoreNullHeaderValues(string headerName, StringValues headerV [MemberData(nameof(ConnectionMiddlewareData))] public async Task WriteAfterConnectionCloseNoops(ListenOptions listenOptions) { - var connectionClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { try { - requestStarted.SetResult(null); + requestStarted.SetResult(); await connectionClosed.Task.DefaultTimeout(); httpContext.Response.ContentLength = 12; await httpContext.Response.WriteAsync("hello, world"); - appCompleted.TrySetResult(null); + appCompleted.TrySetResult(); } catch (Exception ex) { @@ -172,7 +172,7 @@ await connection.Send( await connection.WaitForConnectionClose(); } - connectionClosed.SetResult(null); + connectionClosed.SetResult(); await appCompleted.Task.DefaultTimeout(); await server.StopAsync(); @@ -189,19 +189,19 @@ public async Task ThrowsOnWriteWithRequestAbortedTokenAfterRequestIsAborted(List // Ensure string is long enough to disable write-behind buffering var largeString = new string('a', maxBytesPreCompleted + 1); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestAbortedWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestStartWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAbortedWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestStartWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (var server = new TestServer(async httpContext => { - requestStartWh.SetResult(null); + requestStartWh.SetResult(); var response = httpContext.Response; var request = httpContext.Request; var lifetime = httpContext.Features.Get(); - lifetime.RequestAborted.Register(() => requestAbortedWh.SetResult(null)); + lifetime.RequestAborted.Register(() => requestAbortedWh.SetResult()); await requestAbortedWh.Task.DefaultTimeout(); try @@ -250,10 +250,10 @@ public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedT const int connectionPausedEventId = 4; const int maxRequestBufferSize = 4096; - var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readCallbackUnwired = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var clientClosedConnection = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); TestSink.MessageLogged += context => { @@ -265,7 +265,7 @@ public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedT if (context.EventId.Id == connectionPausedEventId) { - readCallbackUnwired.TrySetResult(null); + readCallbackUnwired.TrySetResult(); } }; @@ -288,7 +288,7 @@ public async Task WritingToConnectionAfterUnobservedCloseTriggersRequestAbortedT using (var server = new TestServer(async context => { - context.RequestAborted.Register(() => requestAborted.SetResult(null)); + context.RequestAborted.Register(() => requestAborted.SetResult()); await clientClosedConnection.Task; @@ -328,7 +328,7 @@ await connection.Send( await readCallbackUnwired.Task.DefaultTimeout(); } - clientClosedConnection.SetResult(null); + clientClosedConnection.SetResult(); await Assert.ThrowsAnyAsync(() => writeTcs.Task).DefaultTimeout(); await server.StopAsync(); @@ -349,14 +349,14 @@ public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions const int responseBodySegmentSize = 65536; const int responseBodySegmentCount = 100; - var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var scratchBuffer = new byte[responseBodySegmentSize]; using (var server = new TestServer(async context => { - context.RequestAborted.Register(() => requestAborted.SetResult(null)); + context.RequestAborted.Register(() => requestAborted.SetResult()); for (var i = 0; i < responseBodySegmentCount; i++) { @@ -365,7 +365,7 @@ public async Task AppCanHandleClientAbortingConnectionMidResponse(ListenOptions } await requestAborted.Task.DefaultTimeout(); - appCompletedTcs.SetResult(null); + appCompletedTcs.SetResult(); }, new TestServiceContext(LoggerFactory), listenOptions)) { using (var connection = server.CreateConnection()) @@ -459,18 +459,18 @@ public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() var responseSize = chunks * chunkSize; var chunkData = new byte[chunkSize]; - var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMinimumDataRateNotSatisfied(It.IsAny(), It.IsAny())) - .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + .Callback(() => responseRateTimeoutMessageLogged.SetResult()); mockKestrelTrace .Setup(trace => trace.ConnectionStop(It.IsAny())) - .Callback(() => connectionStopMessageLogged.SetResult(null)); + .Callback(() => connectionStopMessageLogged.SetResult()); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { @@ -489,7 +489,7 @@ public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate() async Task App(HttpContext context) { appLogger.LogInformation("Request received"); - context.RequestAborted.Register(() => requestAborted.SetResult(null)); + context.RequestAborted.Register(() => requestAborted.SetResult()); context.Response.ContentLength = responseSize; @@ -507,7 +507,7 @@ async Task App(HttpContext context) } catch (OperationCanceledException) { - appFuncCompleted.SetResult(null); + appFuncCompleted.SetResult(); throw; } catch (Exception ex) @@ -559,18 +559,18 @@ public async Task HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate var certificate = TestResources.GetTestCertificate(); - var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var aborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMinimumDataRateNotSatisfied(It.IsAny(), It.IsAny())) - .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + .Callback(() => responseRateTimeoutMessageLogged.SetResult()); mockKestrelTrace .Setup(trace => trace.ConnectionStop(It.IsAny())) - .Callback(() => connectionStopMessageLogged.SetResult(null)); + .Callback(() => connectionStopMessageLogged.SetResult()); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { @@ -594,7 +594,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) { context.RequestAborted.Register(() => { - aborted.SetResult(null); + aborted.SetResult(); }); context.Response.ContentLength = chunks * chunkSize; @@ -608,7 +608,7 @@ void ConfigureListenOptions(ListenOptions listenOptions) } catch (OperationCanceledException) { - appFuncCompleted.SetResult(null); + appFuncCompleted.SetResult(); throw; } finally @@ -646,18 +646,18 @@ public async Task ConnectionClosedWhenBothRequestAndResponseExperienceBackPressu var responseSize = bufferCount * bufferSize; var buffer = new byte[bufferSize]; - var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var copyToAsyncCts = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var responseRateTimeoutMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStopMessageLogged = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var copyToAsyncCts = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ResponseMinimumDataRateNotSatisfied(It.IsAny(), It.IsAny())) - .Callback(() => responseRateTimeoutMessageLogged.SetResult(null)); + .Callback(() => responseRateTimeoutMessageLogged.SetResult()); mockKestrelTrace .Setup(trace => trace.ConnectionStop(It.IsAny())) - .Callback(() => connectionStopMessageLogged.SetResult(null)); + .Callback(() => connectionStopMessageLogged.SetResult()); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) { @@ -679,7 +679,7 @@ async Task App(HttpContext context) { context.RequestAborted.Register(() => { - requestAborted.SetResult(null); + requestAborted.SetResult(); }); try @@ -740,7 +740,7 @@ public async Task ConnectionNotClosedWhenClientSatisfiesMinimumDataRateGivenLarg var chunkData = new byte[chunkSize]; var requestAborted = false; - var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) @@ -773,7 +773,7 @@ async Task App(HttpContext context) await context.Response.BodyWriter.WriteAsync(new Memory(chunkData, 0, chunkData.Length), context.RequestAborted); } - appFuncCompleted.SetResult(null); + appFuncCompleted.SetResult(); } using (var server = new TestServer(App, testContext, listenOptions)) @@ -906,7 +906,7 @@ public async Task ClientCanReceiveFullConnectionCloseResponseWithoutErrorAtALowD var chunkData = new byte[chunkSize]; var requestAborted = false; - var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appFuncCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); var testContext = new TestServiceContext(LoggerFactory, mockKestrelTrace.Object) @@ -939,7 +939,7 @@ async Task App(HttpContext context) await context.Response.BodyWriter.WriteAsync(new Memory(chunkData, 0, chunkData.Length), context.RequestAborted); } - appFuncCompleted.SetResult(null); + appFuncCompleted.SetResult(); } using (var server = new TestServer(App, testContext, listenOptions)) diff --git a/src/Servers/Kestrel/test/FunctionalTests/UnixDomainSocketsTests.cs b/src/Servers/Kestrel/test/FunctionalTests/UnixDomainSocketsTests.cs index a6a49d8b3bdd..7d83625ae2b3 100644 --- a/src/Servers/Kestrel/test/FunctionalTests/UnixDomainSocketsTests.cs +++ b/src/Servers/Kestrel/test/FunctionalTests/UnixDomainSocketsTests.cs @@ -38,7 +38,7 @@ public async Task TestUnixDomainSocket() try { - var serverConnectionCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverConnectionCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); async Task EchoServer(ConnectionContext connection) { @@ -68,7 +68,7 @@ async Task EchoServer(ConnectionContext connection) } finally { - serverConnectionCompletedTcs.TrySetResult(null); + serverConnectionCompletedTcs.TrySetResult(); } } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedRequestTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedRequestTests.cs index 737068b0cc16..5549a1635013 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedRequestTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedRequestTests.cs @@ -842,7 +842,7 @@ await connection.ReceiveEnd( public async Task ClosingConnectionMidChunkPrefixThrows() { var testContext = new TestServiceContext(LoggerFactory); - var readStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); #pragma warning disable CS0618 // Type or member is obsolete var exTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); #pragma warning restore CS0618 // Type or member is obsolete @@ -850,7 +850,7 @@ public async Task ClosingConnectionMidChunkPrefixThrows() await using (var server = new TestServer(async httpContext => { var readTask = httpContext.Request.Body.CopyToAsync(Stream.Null); - readStartedTcs.SetResult(null); + readStartedTcs.SetResult(); try { @@ -892,7 +892,7 @@ await connection.SendAll( [Fact] public async Task ChunkedRequestCallCancelPendingReadWorks() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var testContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(async httpContext => @@ -911,7 +911,7 @@ public async Task ChunkedRequestCallCancelPendingReadWorks() Assert.True((await requestTask).IsCanceled); - tcs.SetResult(null); + tcs.SetResult(); response.Headers["Content-Length"] = new[] { "11" }; @@ -1063,7 +1063,6 @@ await connection.Receive( [Fact] public async Task ChunkedRequestCallCompleteWithExceptionCauses500() { - var tcs = new TaskCompletionSource(); var testContext = new TestServiceContext(LoggerFactory); using (var server = new TestServer(async httpContext => diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedResponseTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedResponseTests.cs index f279141a7d30..dbd56948244f 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedResponseTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedResponseTests.cs @@ -219,7 +219,7 @@ await connection.ReceiveEnd( $"Date: {testContext.DateHeaderValue}", "Transfer-Encoding: chunked", "", - length.ToString("x"), + length.ToString("x"), new string('a', length), "0", "", @@ -485,7 +485,7 @@ public async Task WritesAreFlushedPriorToResponseCompletion() { var testContext = new TestServiceContext(LoggerFactory); - var flushWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var flushWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -514,7 +514,7 @@ await connection.Receive( "Hello ", ""); - flushWh.SetResult(null); + flushWh.SetResult(); await connection.Receive( "6", diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs index 65b804c868e8..16236885f808 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionLimitTests.cs @@ -23,12 +23,12 @@ public class ConnectionLimitTests : LoggedTest [Fact] public async Task ResetsCountWhenConnectionClosed() { - var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var releasedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var releasedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var lockedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(1)); counter.OnLock += (s, e) => lockedTcs.TrySetResult(e); - counter.OnRelease += (s, e) => releasedTcs.TrySetResult(null); + counter.OnRelease += (s, e) => releasedTcs.TrySetResult(); await using (var server = CreateServerWithMaxConnections(async context => { @@ -41,7 +41,7 @@ public async Task ResetsCountWhenConnectionClosed() await connection.SendEmptyGetAsKeepAlive(); ; await connection.Receive("HTTP/1.1 200 OK"); Assert.True(await lockedTcs.Task.DefaultTimeout()); - requestTcs.TrySetResult(null); + requestTcs.TrySetResult(); } } @@ -100,7 +100,7 @@ public async Task UpgradedConnectionsCountsAgainstDifferentLimit() public async Task RejectsConnectionsWhenLimitReached() { const int max = 10; - var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = CreateServerWithMaxConnections(async context => { @@ -136,7 +136,7 @@ public async Task RejectsConnectionsWhenLimitReached() } } - requestTcs.TrySetResult(null); + requestTcs.TrySetResult(); } } } @@ -147,8 +147,8 @@ public async Task ConnectionCountingReturnsToZero() const int count = 100; var opened = 0; var closed = 0; - var openedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var closedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var openedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var closedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var counter = new EventRaisingResourceCounter(ResourceCounter.Quota(uint.MaxValue)); @@ -156,7 +156,7 @@ public async Task ConnectionCountingReturnsToZero() { if (e && Interlocked.Increment(ref opened) >= count) { - openedTcs.TrySetResult(null); + openedTcs.TrySetResult(); } }; @@ -164,7 +164,7 @@ public async Task ConnectionCountingReturnsToZero() { if (Interlocked.Increment(ref closed) >= count) { - closedTcs.TrySetResult(null); + closedTcs.TrySetResult(); } }; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs index f73c96c6e754..03b1ea195bee 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ConnectionMiddlewareTests.cs @@ -161,7 +161,7 @@ public async Task ImmediateShutdownAfterOnConnectionAsyncDoesNotCrash(RequestDel [Fact] public async Task ImmediateShutdownDuringOnConnectionAsyncDoesNotCrash() { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); listenOptions.Use(next => { @@ -182,7 +182,7 @@ public async Task ImmediateShutdownDuringOnConnectionAsyncDoesNotCrash() { stopTask = server.StopAsync(); - tcs.TrySetResult(null); + tcs.TrySetResult(); } await stopTask; diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs index 2517a55b1560..43a3f9d7a298 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2ConnectionTests.cs @@ -210,7 +210,7 @@ await ExpectAsync(Http2FrameType.HEADERS, [Fact] public async Task StreamPool_SingleStream_ReturnedToPool() { - var serverTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(async context => { @@ -223,7 +223,7 @@ await InitializeConnectionAsync(async context => await StartStreamAsync(1, _browserRequestHeaders, endStream: true); var stream = _connection._streams[1]; - serverTcs.SetResult(null); + serverTcs.SetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 36, @@ -303,7 +303,7 @@ await ExpectAsync(Http2FrameType.PING, [QuarantinedTest] public async Task StreamPool_MultipleStreamsInSequence_PooledStreamReused() { - TaskCompletionSource appDelegateTcs = null; + TaskCompletionSource appDelegateTcs = null; await InitializeConnectionAsync(async context => { @@ -312,13 +312,13 @@ await InitializeConnectionAsync(async context => Assert.Equal(0, _connection.StreamPool.Count); - appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await StartStreamAsync(1, _browserRequestHeaders, endStream: true); // Get the in progress stream var stream = _connection._streams[1]; - appDelegateTcs.TrySetResult(null); + appDelegateTcs.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 36, @@ -330,13 +330,13 @@ await ExpectAsync(Http2FrameType.HEADERS, Assert.True(_connection.StreamPool.TryPeek(out var pooledStream)); Assert.Equal(stream, pooledStream); - appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + appDelegateTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await StartStreamAsync(3, _browserRequestHeaders, endStream: true); // New stream has been taken from the pool Assert.Equal(0, _connection.StreamPool.Count); - appDelegateTcs.TrySetResult(null); + appDelegateTcs.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 6, @@ -368,7 +368,7 @@ await ExpectAsync(Http2FrameType.PING, [QuarantinedTest] public async Task StreamPool_StreamIsInvalidState_DontReturnedToPool() { - var serverTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var serverTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(async context => { @@ -381,7 +381,7 @@ await InitializeConnectionAsync(async context => await StartStreamAsync(1, _browserRequestHeaders, endStream: true); var stream = _connection._streams[1]; - serverTcs.SetResult(null); + serverTcs.SetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 32, @@ -933,10 +933,10 @@ await ExpectAsync(Http2FrameType.DATA, [Fact] public async Task DATA_Received_Multiplexed_AppMustNotBlockOtherFrames() { - var stream1Read = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var stream1ReadFinished = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var stream3Read = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var stream3ReadFinished = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var stream1Read = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var stream1ReadFinished = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var stream3Read = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var stream3ReadFinished = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(async context => { @@ -944,13 +944,13 @@ await InitializeConnectionAsync(async context => var read = await context.Request.Body.ReadAsync(new byte[10], 0, 10); if (context.Features.Get().StreamId == 1) { - stream1Read.TrySetResult(null); + stream1Read.TrySetResult(); await stream1ReadFinished.Task.DefaultTimeout(); } else { - stream3Read.TrySetResult(null); + stream3Read.TrySetResult(); await stream3ReadFinished.Task.DefaultTimeout(); } @@ -966,7 +966,7 @@ await InitializeConnectionAsync(async context => await SendDataAsync(3, _helloBytes, endStream: true); await stream3Read.Task.DefaultTimeout(); - stream3ReadFinished.TrySetResult(null); + stream3ReadFinished.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 32, @@ -981,7 +981,7 @@ await ExpectAsync(Http2FrameType.DATA, withFlags: (byte)Http2DataFrameFlags.END_STREAM, withStreamId: 3); - stream1ReadFinished.TrySetResult(null); + stream1ReadFinished.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 2, @@ -1380,15 +1380,15 @@ await WaitForConnectionErrorAsync( public async Task Frame_MultipleStreams_CanBeCreatedIfClientCountIsLessThanActualMaxStreamCount() { _serviceContext.ServerOptions.Limits.Http2.MaxStreamsPerConnection = 1; - var firstRequestBlock = new TaskCompletionSource(); - var firstRequestReceived = new TaskCompletionSource(); + var firstRequestBlock = new TaskCompletionSource(); + var firstRequestReceived = new TaskCompletionSource(); var makeFirstRequestWait = false; await InitializeConnectionAsync(async context => { if (!makeFirstRequestWait) { makeFirstRequestWait = true; - firstRequestReceived.SetResult(null); + firstRequestReceived.SetResult(); await firstRequestBlock.Task.DefaultTimeout(); } }); @@ -1405,7 +1405,7 @@ await ExpectAsync(Http2FrameType.HEADERS, withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM), withStreamId: 3); - firstRequestBlock.SetResult(null); + firstRequestBlock.SetResult(); await StopConnectionAsync(3, ignoreNonGoAwayFrames: false); } @@ -1414,7 +1414,7 @@ await ExpectAsync(Http2FrameType.HEADERS, public async Task Frame_MultipleStreams_RequestsNotFinished_EnhanceYourCalm() { _serviceContext.ServerOptions.Limits.Http2.MaxStreamsPerConnection = 1; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(async context => { await tcs.Task.DefaultTimeout(); @@ -1431,7 +1431,7 @@ await WaitForStreamErrorAsync( expectedErrorCode: Http2ErrorCode.ENHANCE_YOUR_CALM, expectedErrorMessage: CoreStrings.Http2TellClientToCalmDown); - tcs.SetResult(null); + tcs.SetResult(); await StopConnectionAsync(5, ignoreNonGoAwayFrames: false); } @@ -1542,7 +1542,7 @@ await InitializeConnectionAsync(async context => } } - _runningStreams[streamId].SetResult(null); + _runningStreams[streamId].SetResult(); } catch (Exception ex) { @@ -1772,22 +1772,22 @@ await ExpectAsync(Http2FrameType.DATA, [Fact] public async Task HEADERS_Received_AppCannotBlockOtherFrames() { - var firstRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var finishFirstRequest = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var secondRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var finishSecondRequest = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var firstRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var finishFirstRequest = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var secondRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var finishSecondRequest = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(async context => { if (!firstRequestReceived.Task.IsCompleted) { - firstRequestReceived.TrySetResult(null); + firstRequestReceived.TrySetResult(); await finishFirstRequest.Task.DefaultTimeout(); } else { - secondRequestReceived.TrySetResult(null); + secondRequestReceived.TrySetResult(); await finishSecondRequest.Task.DefaultTimeout(); } @@ -1801,14 +1801,14 @@ await InitializeConnectionAsync(async context => await secondRequestReceived.Task.DefaultTimeout(); - finishSecondRequest.TrySetResult(null); + finishSecondRequest.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 36, withFlags: (byte)(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.END_STREAM), withStreamId: 3); - finishFirstRequest.TrySetResult(null); + finishFirstRequest.TrySetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 6, @@ -1971,7 +1971,7 @@ public async Task HEADERS_OverMaxStreamLimit_Refused() _connection.ServerSettings.MaxConcurrentStreams = 1; - var requestBlocker = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestBlocker = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await InitializeConnectionAsync(context => requestBlocker.Task); await StartStreamAsync(1, _browserRequestHeaders, endStream: true); @@ -1980,7 +1980,7 @@ public async Task HEADERS_OverMaxStreamLimit_Refused() await WaitForStreamErrorAsync(3, Http2ErrorCode.REFUSED_STREAM, CoreStrings.Http2ErrorMaxStreams); - requestBlocker.SetResult(0); + requestBlocker.SetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 36, @@ -2533,15 +2533,15 @@ await InitializeConnectionAsync(async context => { var streamId = context.Features.Get().StreamId; - var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); context.RequestAborted.Register(() => { lock (_abortedStreamIdsLock) { _abortedStreamIds.Add(streamId); - abortedTcs.SetResult(null); + abortedTcs.SetResult(); } }); @@ -2559,11 +2559,11 @@ await InitializeConnectionAsync(async context => await context.Response.Body.WriteAsync(_maxData, 0, remainingBytesBeforeBackpressure + 1); - writeTcs.SetResult(null); + writeTcs.SetResult(); await abortedTcs.Task; - _runningStreams[streamId].SetResult(null); + _runningStreams[streamId].SetResult(); } catch (Exception ex) { @@ -2651,15 +2651,15 @@ await InitializeConnectionAsync(async context => { var streamId = context.Features.Get().StreamId; - var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); context.RequestAborted.Register(() => { lock (_abortedStreamIdsLock) { _abortedStreamIds.Add(streamId); - abortedTcs.SetResult(null); + abortedTcs.SetResult(); } }); @@ -2667,11 +2667,11 @@ await InitializeConnectionAsync(async context => { writeTasks[streamId] = writeTcs.Task; await context.Response.Body.WriteAsync(_helloWorldBytes, 0, _helloWorldBytes.Length); - writeTcs.SetResult(null); + writeTcs.SetResult(); await abortedTcs.Task; - _runningStreams[streamId].SetResult(null); + _runningStreams[streamId].SetResult(); } catch (Exception ex) { @@ -3481,15 +3481,15 @@ await InitializeConnectionAsync(async context => { var streamId = context.Features.Get().StreamId; - var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); context.RequestAborted.Register(() => { lock (_abortedStreamIdsLock) { _abortedStreamIds.Add(streamId); - abortedTcs.SetResult(null); + abortedTcs.SetResult(); } }); @@ -3507,11 +3507,11 @@ await InitializeConnectionAsync(async context => await context.Response.Body.WriteAsync(_maxData, 0, remainingBytesBeforeBackpressure + 1); - writeTcs.SetResult(null); + writeTcs.SetResult(); await abortedTcs.Task; - _runningStreams[streamId].SetResult(null); + _runningStreams[streamId].SetResult(); } catch (Exception ex) { @@ -3583,15 +3583,15 @@ await InitializeConnectionAsync(async context => { var streamId = context.Features.Get().StreamId; - var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var abortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); context.RequestAborted.Register(() => { lock (_abortedStreamIdsLock) { _abortedStreamIds.Add(streamId); - abortedTcs.SetResult(null); + abortedTcs.SetResult(); } }); @@ -3599,11 +3599,11 @@ await InitializeConnectionAsync(async context => { writeTasks[streamId] = writeTcs.Task; await context.Response.Body.WriteAsync(_helloWorldBytes, 0, _helloWorldBytes.Length); - writeTcs.SetResult(null); + writeTcs.SetResult(); await abortedTcs.Task; - _runningStreams[streamId].SetResult(null); + _runningStreams[streamId].SetResult(); } catch (Exception ex) { @@ -3811,8 +3811,8 @@ public async Task WINDOW_UPDATE_Received_OnConnection_Respected() // This way we're sure that if Response.Body.WriteAsync returns an incomplete task, it's because // of the flow control window and not Pipe backpressure. var expectingDataSem = new SemaphoreSlim(0); - var backpressureObservedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var backpressureReleasedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var backpressureObservedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var backpressureReleasedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); // Double the stream window to be 128KiB so it doesn't interfere with the rest of the test. _clientSettings.InitialWindowSize = Http2PeerSettings.DefaultInitialWindowSize * 2; @@ -3834,10 +3834,10 @@ await InitializeConnectionAsync(async context => var lastWriteTask = context.Response.Body.WriteAsync(_maxData, 0, _maxData.Length); Assert.False(lastWriteTask.IsCompleted); - backpressureObservedTcs.TrySetResult(null); + backpressureObservedTcs.TrySetResult(); await lastWriteTask; - backpressureReleasedTcs.TrySetResult(null); + backpressureReleasedTcs.TrySetResult(); } catch (Exception ex) { @@ -4325,7 +4325,7 @@ await ExpectAsync(Http2FrameType.HEADERS, withStreamId: 1); // Send a blocked request - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); task = tcs.Task; await StartStreamAsync(3, _browserRequestHeaders, endStream: false); @@ -4344,7 +4344,7 @@ await ExpectAsync(Http2FrameType.HEADERS, Assert.False(result.IsCompleted); // Unblock the request and ProcessRequestsAsync - tcs.TrySetResult(null); + tcs.TrySetResult(); await _connectionTask; // Assert connection's Input pipe is completed diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs index 4e0dd12137ec..56f42251ee63 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs @@ -715,7 +715,7 @@ await InitializeConnectionAsync(async context => [Fact] public async Task ContentLength_Received_MultipleDataFrame_ReadViaPipeAndStream_Verified() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var headers = new[] { new KeyValuePair(HeaderNames.Method, "POST"), @@ -729,7 +729,7 @@ await InitializeConnectionAsync(async context => Assert.Equal(1, readResult.Buffer.Length); context.Request.BodyReader.AdvanceTo(readResult.Buffer.End); - tcs.SetResult(null); + tcs.SetResult(); var buffer = new byte[100]; @@ -1256,7 +1256,7 @@ await ExpectAsync(Http2FrameType.DATA, [Fact] public async Task StartAsync_WithoutFinalFlushDoesNotFlushUntilResponseEnd() { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var headers = new[] { @@ -1285,7 +1285,7 @@ await InitializeConnectionAsync(async context => withFlags: (byte)Http2DataFrameFlags.NONE, withStreamId: 1); - tcs.SetResult(null); + tcs.SetResult(); await ExpectAsync(Http2FrameType.DATA, withLength: 0, @@ -2335,7 +2335,7 @@ await InitializeConnectionAsync(async context => await context.Response.Body.WriteAsync(new byte[10], 0, 10); - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }); await StartStreamAsync(1, _browserRequestHeaders, endStream: true); @@ -2370,7 +2370,7 @@ await InitializeConnectionAsync(async context => context.Response.BodyWriter.Advance(10); await context.Response.BodyWriter.FlushAsync(); - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }); await StartStreamAsync(1, _browserRequestHeaders, endStream: true); @@ -2406,7 +2406,7 @@ await InitializeConnectionAsync(async context => _abortedStreamIds.Add(streamIdFeature.StreamId); } - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); } catch (Exception ex) { @@ -2449,7 +2449,7 @@ await InitializeConnectionAsync(async context => _abortedStreamIds.Add(streamIdFeature.StreamId); } - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); } catch (Exception ex) { @@ -2483,7 +2483,7 @@ await InitializeConnectionAsync(async context => _abortedStreamIds.Add(streamIdFeature.StreamId); } - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }); context.Abort(); @@ -2523,7 +2523,7 @@ await InitializeConnectionAsync(async context => _abortedStreamIds.Add(streamIdFeature.StreamId); } - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }); await context.Response.Body.WriteAsync(new byte[10], 0, 10); @@ -3926,7 +3926,7 @@ await ExpectAsync(Http2FrameType.DATA, [Fact] public async Task CompleteAsync_AdvanceAfterComplete_AdvanceThrows() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var headers = new[] { new KeyValuePair(HeaderNames.Method, "GET"), @@ -3943,7 +3943,7 @@ await InitializeConnectionAsync(async context => } catch (InvalidOperationException) { - tcs.SetResult(null); + tcs.SetResult(); return; } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index 1a9cbba99883..c379a4f4dd0a 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -130,14 +130,14 @@ protected static IEnumerable> ReadRateRequestHeader internal readonly Mock _mockTimeoutHandler = new Mock(); internal readonly Mock _mockTimeoutControl; - protected readonly ConcurrentDictionary> _runningStreams = new ConcurrentDictionary>(); + protected readonly ConcurrentDictionary _runningStreams = new ConcurrentDictionary(); protected readonly Dictionary _receivedHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); protected readonly Dictionary _receivedTrailers = new Dictionary(StringComparer.OrdinalIgnoreCase); protected readonly Dictionary _decodedHeaders = new Dictionary(StringComparer.OrdinalIgnoreCase); protected readonly HashSet _abortedStreamIds = new HashSet(); protected readonly object _abortedStreamIdsLock = new object(); - protected readonly TaskCompletionSource _closingStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - protected readonly TaskCompletionSource _closedStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + protected readonly TaskCompletionSource _closingStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + protected readonly TaskCompletionSource _closedStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); protected readonly RequestDelegate _noopApplication; protected readonly RequestDelegate _readHeadersApplication; @@ -174,10 +174,10 @@ public Http2TestBase() _mockKestrelTrace .Setup(m => m.Http2ConnectionClosing(It.IsAny())) - .Callback(() => _closingStateReached.SetResult(null)); + .Callback(() => _closingStateReached.SetResult()); _mockKestrelTrace .Setup(m => m.Http2ConnectionClosed(It.IsAny(), It.IsAny())) - .Callback(() => _closedStateReached.SetResult(null)); + .Callback(() => _closedStateReached.SetResult()); _mockConnectionContext.Setup(c => c.Abort(It.IsAny())).Callback(ex => { @@ -300,7 +300,7 @@ public Http2TestBase() await sem.WaitAsync().DefaultTimeout(); - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }; _waitForAbortFlushingApplication = async context => @@ -322,7 +322,7 @@ public Http2TestBase() await context.Response.Body.FlushAsync(); - _runningStreams[streamIdFeature.StreamId].TrySetResult(null); + _runningStreams[streamIdFeature.StreamId].TrySetResult(); }; _readRateApplication = async context => @@ -509,7 +509,7 @@ protected void TriggerTick(DateTimeOffset now) protected Task StartStreamAsync(int streamId, IEnumerable> headers, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _runningStreams[streamId] = tcs; writableBuffer.WriteStartStream(streamId, _hpackEncoder, GetHeadersEnumerator(headers), _headerEncodingBuffer, endStream); @@ -519,7 +519,7 @@ protected Task StartStreamAsync(int streamId, IEnumerable headerData, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _runningStreams[streamId] = tcs; writableBuffer.WriteStartStream(streamId, headerData, endStream); @@ -538,7 +538,7 @@ protected Task StartStreamAsync(int streamId, Span headerData, bool endStr protected Task SendHeadersWithPaddingAsync(int streamId, IEnumerable> headers, byte padLength, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _runningStreams[streamId] = tcs; var frame = new Http2Frame(); @@ -580,7 +580,7 @@ protected Task SendHeadersWithPaddingAsync(int streamId, IEnumerable> headers, byte priority, int streamDependency, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _runningStreams[streamId] = tcs; var frame = new Http2Frame(); @@ -625,7 +625,7 @@ protected Task SendHeadersWithPriorityAsync(int streamId, IEnumerable> headers, byte padLength, byte priority, int streamDependency, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _runningStreams[streamId] = tcs; var frame = new Http2Frame(); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TimeoutTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TimeoutTests.cs index e9af94a606e0..99bbd21ea588 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TimeoutTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TimeoutTests.cs @@ -87,11 +87,11 @@ public async Task HEADERS_NotReceivedAfterFirstRequest_WithinKeepAliveTimeout_Cl // The KeepAlive timeout is set when the stream completes processing on a background thread, so we need to hook the // keep-alive set afterwards to make a reliable test. - var setTimeoutTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var setTimeoutTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _mockTimeoutControl.Setup(c => c.SetTimeout(It.IsAny(), TimeoutReason.KeepAlive)).Callback((t, r) => { _timeoutControl.SetTimeout(t, r); - setTimeoutTcs.SetResult(null); + setTimeoutTcs.SetResult(); }); // Send continuation frame to verify intermediate request header timeout doesn't interfere with keep-alive timeout. @@ -851,7 +851,7 @@ public async Task DATA_Received_SlowlyDueToConnectionFlowControl_DoesNotAbortCon var initialConnectionWindowSize = _serviceContext.ServerOptions.Limits.Http2.InitialConnectionWindowSize; var framesConnectionInWindow = initialConnectionWindowSize / Http2PeerSettings.DefaultMaxFrameSize; - var backpressureTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var backpressureTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockSystemClock = _serviceContext.MockSystemClock; var limits = _serviceContext.ServerOptions.Limits; @@ -900,7 +900,7 @@ await ExpectAsync(Http2FrameType.DATA, _mockTimeoutHandler.Verify(h => h.OnTimeout(It.IsAny()), Times.Never); // Opening the connection window starts the read rate timeout enforcement after that point. - backpressureTcs.SetResult(null); + backpressureTcs.SetResult(); await ExpectAsync(Http2FrameType.HEADERS, withLength: 6, diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpConnectionManagerTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpConnectionManagerTests.cs index 3a72e0d2be8a..60d95a90c2f6 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpConnectionManagerTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpConnectionManagerTests.cs @@ -45,7 +45,7 @@ public async Task CriticalErrorLoggedIfApplicationDoesntComplete() await using (var server = new TestServer(context => { appStartedWh.Release(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); return tcs.Task; }, testContext)) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs index def3545778de..adef6d78e832 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/HttpsTests.cs @@ -221,7 +221,7 @@ await sslStream.AuthenticateAsClientAsync("127.0.0.1", clientCertificates: null, [QuarantinedTest] public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnectionIsAborted() { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var loggerProvider = new HandshakeErrorLoggerProvider(); LoggerFactory.AddProvider(loggerProvider); @@ -231,7 +231,7 @@ public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnecti try { await httpContext.Response.WriteAsync($"hello, world"); - tcs.SetResult(null); + tcs.SetResult(); } catch (Exception ex) { @@ -317,7 +317,7 @@ public async Task HandshakeTimesOutAndIsLoggedAsDebug() var testContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(testContext.ConnectionManager); - var handshakeStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var handshakeStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); TimeSpan handshakeTimeout = default; await using (var server = new TestServer(context => Task.CompletedTask, @@ -329,7 +329,7 @@ public async Task HandshakeTimesOutAndIsLoggedAsDebug() o.ServerCertificate = new X509Certificate2(TestResources.GetTestCertificate()); o.OnAuthenticate = (_, __) => { - handshakeStartedTcs.SetResult(null); + handshakeStartedTcs.SetResult(); }; handshakeTimeout = o.HandshakeTimeout; @@ -488,13 +488,13 @@ private class HttpsConnectionFilterLogger : ILogger { public LogLevel LastLogLevel { get; set; } public EventId LastEventId { get; set; } - public TaskCompletionSource LogTcs { get; } = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + 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; - LogTcs.SetResult(null); + LogTcs.SetResult(); } public bool IsEnabled(LogLevel logLevel) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/KeepAliveTimeoutTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/KeepAliveTimeoutTests.cs index 34f3932129cd..b997898216ea 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/KeepAliveTimeoutTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/KeepAliveTimeoutTests.cs @@ -22,7 +22,7 @@ public class KeepAliveTimeoutTests : LoggedTest private static readonly TimeSpan _longDelay = TimeSpan.FromSeconds(30); private static readonly TimeSpan _shortDelay = TimeSpan.FromSeconds(_longDelay.TotalSeconds / 10); - private readonly TaskCompletionSource _firstRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _firstRequestReceived = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); [Fact] public async Task ConnectionClosedWhenKeepAliveTimeoutExpires() @@ -240,7 +240,7 @@ private async Task App(HttpContext httpContext, CancellationToken longRunningCt, var responseStream = httpContext.Response.Body; var responseBytes = Encoding.ASCII.GetBytes("hello, world"); - _firstRequestReceived.TrySetResult(null); + _firstRequestReceived.TrySetResult(); if (httpContext.Request.Path == "/longrunning") { @@ -285,8 +285,8 @@ private static Task CancellationTokenAsTask(CancellationToken token) return Task.CompletedTask; } - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - token.Register(() => tcs.SetResult(null)); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + token.Register(() => tcs.SetResult()); return tcs.Task; } } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestBodyTimeoutTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestBodyTimeoutTests.cs index 93a0c7ff56db..139c786c3a90 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestBodyTimeoutTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestBodyTimeoutTests.cs @@ -25,7 +25,7 @@ public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRat var serviceContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(serviceContext.ConnectionManager); - var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(context => { @@ -56,7 +56,7 @@ public async Task RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRat // return context.Request.Body.ReadAsync(new byte[1], 0, 1); var readTask = context.Request.Body.ReadAsync(new byte[1], 0, 1); - appRunningEvent.SetResult(null); + appRunningEvent.SetResult(); return readTask; }, serviceContext)) { @@ -104,13 +104,13 @@ public async Task RequestTimesOutWhenNotDrainedWithinDrainTimeoutPeriod() date.OnHeartbeat(clock.UtcNow); serviceContext.DateHeaderValueManager = date; - var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appRunningEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(context => { context.Features.Get().MinDataRate = null; - appRunningEvent.SetResult(null); + appRunningEvent.SetResult(); return Task.CompletedTask; }, serviceContext)) { @@ -146,8 +146,8 @@ public async Task ConnectionClosedEvenIfAppSwallowsException() var serviceContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(serviceContext.ConnectionManager); - var appRunningTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var exceptionSwallowedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appRunningTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var exceptionSwallowedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { @@ -157,7 +157,7 @@ public async Task ConnectionClosedEvenIfAppSwallowsException() // See comment in RequestTimesOutWhenRequestBodyNotReceivedAtSpecifiedMinimumRate for // why we call ReadAsync before setting the appRunningEvent. var readTask = context.Request.Body.ReadAsync(new byte[1], 0, 1); - appRunningTcs.SetResult(null); + appRunningTcs.SetResult(); try { @@ -165,7 +165,7 @@ public async Task ConnectionClosedEvenIfAppSwallowsException() } catch (Microsoft.AspNetCore.Http.BadHttpRequestException ex) when (ex.StatusCode == 408) { - exceptionSwallowedTcs.SetResult(null); + exceptionSwallowedTcs.SetResult(); } catch (Exception ex) { diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs index 41d9cc824825..3ada9a09a6cf 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs @@ -84,8 +84,8 @@ public async Task PipesAreNotPersistedAcrossRequests() [Fact] public async Task RequestBodyReadAsyncCanBeCancelled() { - var helloTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var helloTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var readTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var cts = new CancellationTokenSource(); await using (var server = new TestServer(async context => @@ -97,7 +97,7 @@ public async Task RequestBodyReadAsyncCanBeCancelled() Assert.Equal("Hello ", Encoding.ASCII.GetString(buffer, 0, 6)); - helloTcs.TrySetResult(null); + helloTcs.TrySetResult(); } catch (Exception ex) { @@ -108,7 +108,7 @@ public async Task RequestBodyReadAsyncCanBeCancelled() try { var task = context.Request.Body.ReadAsync(buffer, 0, buffer.Length, cts.Token); - readTcs.TrySetResult(null); + readTcs.TrySetResult(); await task; context.Response.ContentLength = 12; @@ -1052,19 +1052,19 @@ await connection.ReceiveEnd( public async Task ContentLengthReadAsyncSingleBytesAtATime() { var testContext = new TestServiceContext(LoggerFactory); - var tcs = new TaskCompletionSource(); - var tcs2 = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); + var tcs2 = new TaskCompletionSource(); await using (var server = new TestServer(async httpContext => { var readResult = await httpContext.Request.BodyReader.ReadAsync(); Assert.Equal(3, readResult.Buffer.Length); - tcs.SetResult(null); + tcs.SetResult(); httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); readResult = await httpContext.Request.BodyReader.ReadAsync(); httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); - tcs2.SetResult(null); + tcs2.SetResult(); readResult = await httpContext.Request.BodyReader.ReadAsync(); Assert.Equal(5, readResult.Buffer.Length); @@ -1494,8 +1494,8 @@ await connection.ReceiveEnd( [Fact] public async Task DoesNotEnforceRequestBodyMinimumDataRateOnUpgradedRequest() { - var appEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var delayEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var delayEvent = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var serviceContext = new TestServiceContext(LoggerFactory); var heartbeatManager = new HeartbeatManager(serviceContext.ConnectionManager); @@ -1506,7 +1506,7 @@ public async Task DoesNotEnforceRequestBodyMinimumDataRateOnUpgradedRequest() using (var stream = await context.Features.Get().UpgradeAsync()) { - appEvent.SetResult(null); + appEvent.SetResult(); // Read once to go through one set of TryPauseTimingReads()/TryResumeTimingReads() calls await stream.ReadAsync(new byte[1], 0, 1); @@ -1536,7 +1536,7 @@ await connection.Send( serviceContext.MockSystemClock.UtcNow += TimeSpan.FromSeconds(5); heartbeatManager.OnHeartbeat(serviceContext.SystemClock.UtcNow); - delayEvent.SetResult(null); + delayEvent.SetResult(); await connection.Send("b"); @@ -1766,7 +1766,7 @@ await connection.Send( [Fact] public async Task ContentLengthRequestCallCancelPendingReadWorks() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var testContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(async httpContext => @@ -1785,7 +1785,7 @@ public async Task ContentLengthRequestCallCancelPendingReadWorks() Assert.True((await requestTask).IsCanceled); - tcs.SetResult(null); + tcs.SetResult(); response.Headers["Content-Length"] = new[] { "11" }; @@ -1863,7 +1863,7 @@ public async Task ContentLengthRequestCallCompleteDoesNotCauseException() { var testContext = new TestServiceContext(LoggerFactory); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); await using (var server = new TestServer(async httpContext => { var request = httpContext.Request; @@ -1873,7 +1873,7 @@ public async Task ContentLengthRequestCallCompleteDoesNotCauseException() httpContext.Request.BodyReader.Complete(); - tcs.SetResult(null); + tcs.SetResult(); }, testContext)) { @@ -1902,7 +1902,6 @@ await connection.Receive( [Fact] public async Task ContentLengthCallCompleteWithExceptionCauses500() { - var tcs = new TaskCompletionSource(); var testContext = new TestServiceContext(LoggerFactory); await using (var server = new TestServer(async httpContext => diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs index 9861a0fe1ab6..91e85ca0a858 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseDrainingTests.cs @@ -39,12 +39,12 @@ public async Task ConnectionClosedWhenResponseNotDrainedAtMinimumDataRate(Listen { var transportConnection = connection.TransportConnection; - var outputBufferedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var outputBufferedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); #pragma warning disable 0618 // TODO: Repalce OnWriterCompleted transportConnection.Output.OnWriterCompleted((ex, state) => { - ((TaskCompletionSource)state).SetResult(null); + ((TaskCompletionSource)state).SetResult(); }, outputBufferedTcs); #pragma warning restore diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs index c95839996a11..d2e75cdc16c5 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/ResponseTests.cs @@ -34,14 +34,14 @@ public class ResponseTests : TestApplicationErrorLoggerLoggedTest public async Task OnCompleteCalledEvenWhenOnStartingNotCalled() { var onStartingCalled = false; - TaskCompletionSource onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + TaskCompletionSource onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(context => { context.Response.OnStarting(() => Task.Run(() => onStartingCalled = true)); context.Response.OnCompleted(() => Task.Run(() => { - onCompletedTcs.SetResult(null); + onCompletedTcs.SetResult(); })); // Prevent OnStarting call (see HttpProtocol.ProcessRequestsAsync()). @@ -141,8 +141,8 @@ public async Task ResponseBodyWriteAsyncCanBeCancelled() { var serviceContext = new TestServiceContext(LoggerFactory); var cts = new CancellationTokenSource(); - var appTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var writeBlockedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var writeBlockedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { @@ -164,7 +164,7 @@ public async Task ResponseBodyWriteAsyncCanBeCancelled() completedTask = await Task.WhenAny(writeTask, timerTask); } - writeBlockedTcs.TrySetResult(null); + writeBlockedTcs.TrySetResult(); await writeTask; } @@ -175,7 +175,7 @@ public async Task ResponseBodyWriteAsyncCanBeCancelled() } finally { - appTcs.TrySetResult(null); + appTcs.TrySetResult(); } }, serviceContext)) { @@ -331,7 +331,7 @@ await connection.Receive($"HTTP/1.1 200 OK", [Fact] public async Task OnCompletedShouldNotBlockAResponse() { - var delayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var delayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { @@ -361,20 +361,20 @@ await connection.Receive($"HTTP/1.1 200 OK", ""); } - delayTcs.SetResult(null); + delayTcs.SetResult(); } } [Fact] public async Task InvalidChunkedEncodingInRequestShouldNotBlockOnCompleted() { - var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(httpContext => { httpContext.Response.OnCompleted(() => Task.Run(() => { - onCompletedTcs.SetResult(null); + onCompletedTcs.SetResult(); })); return Task.CompletedTask; }, new TestServiceContext(LoggerFactory))) @@ -644,11 +644,11 @@ public async Task ResponseBodyNotWrittenOnHeadResponseAndLoggedOnlyOnce() { const string response = "hello, world"; - var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockKestrelTrace = new Mock(); mockKestrelTrace .Setup(trace => trace.ConnectionHeadResponseBodyWrite(It.IsAny(), response.Length)) - .Callback((connectionId, count) => logTcs.SetResult(null)); + .Callback((connectionId, count) => logTcs.SetResult()); await using (var server = new TestServer(async httpContext => { @@ -831,13 +831,13 @@ await connection.ReceiveEnd( [Fact] public async Task WhenAppWritesLessThanContentLengthErrorLogged() { - var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockTrace = new Mock(); mockTrace .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((connectionId, requestId, ex) => { - logTcs.SetResult(null); + logTcs.SetResult(); }); await using (var server = new TestServer(async httpContext => @@ -886,13 +886,13 @@ public async Task WhenAppWritesLessThanContentLengthCompleteThrowsAndErrorLogged { InvalidOperationException completeEx = null; - var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var logTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockTrace = new Mock(); mockTrace .Setup(trace => trace.ApplicationError(It.IsAny(), It.IsAny(), It.IsAny())) .Callback((connectionId, requestId, ex) => { - logTcs.SetResult(null); + logTcs.SetResult(); }); await using (var server = new TestServer(async httpContext => @@ -944,14 +944,14 @@ await connection.Receive( [Fact] public async Task WhenAppWritesLessThanContentLengthButRequestIsAbortedErrorNotLogged() { - var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var requestAborted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockTrace = new Mock(); await using (var server = new TestServer(async httpContext => { httpContext.RequestAborted.Register(() => { - requestAborted.SetResult(null); + requestAborted.SetResult(); }); httpContext.Response.ContentLength = 12; @@ -1165,7 +1165,7 @@ await connection.Receive( [Fact] public async Task HeadResponseBodyNotWrittenWithAsyncWrite() { - var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -1188,7 +1188,7 @@ await connection.Receive( "", ""); - flushed.SetResult(null); + flushed.SetResult(); } } } @@ -1196,7 +1196,7 @@ await connection.Receive( [Fact] public async Task HeadResponseBodyNotWrittenWithSyncWrite() { - var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var serviceContext = new TestServiceContext(LoggerFactory) { ServerOptions = { AllowSynchronousIO = true } }; @@ -1221,7 +1221,7 @@ await connection.Receive( "", ""); - flushed.SetResult(null); + flushed.SetResult(); } } } @@ -1229,7 +1229,7 @@ await connection.Receive( [Fact] public async Task ZeroLengthWritesFlushHeaders() { - var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var flushed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -1253,7 +1253,7 @@ await connection.Receive( "", ""); - flushed.SetResult(null); + flushed.SetResult(); await connection.Receive("hello, world"); } @@ -1264,7 +1264,7 @@ await connection.Receive( public async Task AppCanWriteOwnBadRequestResponse() { var expectedResponse = string.Empty; - var responseWritten = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var responseWritten = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -1278,7 +1278,7 @@ public async Task AppCanWriteOwnBadRequestResponse() httpContext.Response.StatusCode = StatusCodes.Status400BadRequest; httpContext.Response.ContentLength = ex.Message.Length; await httpContext.Response.WriteAsync(ex.Message); - responseWritten.SetResult(null); + responseWritten.SetResult(); } }, new TestServiceContext(LoggerFactory))) { @@ -2257,7 +2257,7 @@ await connection.Receive( public async Task OnStartingThrowsInsideOnStartingCallbacksRuns() { var testContext = new TestServiceContext(LoggerFactory); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -2266,7 +2266,7 @@ public async Task OnStartingThrowsInsideOnStartingCallbacksRuns() { response.OnStarting(state2 => { - tcs.TrySetResult(null); + tcs.TrySetResult(); return Task.CompletedTask; }, null); @@ -2301,7 +2301,7 @@ await connection.Receive( public async Task OnCompletedThrowsInsideOnCompletedCallbackRuns() { var testContext = new TestServiceContext(LoggerFactory); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -2310,7 +2310,7 @@ public async Task OnCompletedThrowsInsideOnCompletedCallbackRuns() { response.OnCompleted(state2 => { - tcs.TrySetResult(null); + tcs.TrySetResult(); return Task.CompletedTask; }, @@ -2565,8 +2565,8 @@ public async Task AppAbortViaIConnectionLifetimeFeatureIsLogged() feature.Abort(); // Ensure the response doesn't get flush before the abort is observed. - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - feature.ConnectionClosed.Register(() => tcs.TrySetResult(null)); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + feature.ConnectionClosed.Register(() => tcs.TrySetResult()); return tcs.Task; }, testContext)) @@ -2846,7 +2846,7 @@ public async Task StartAsyncWithoutFlushingDoesNotFlush() { var testContext = new TestServiceContext(LoggerFactory); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async httpContext => { @@ -2874,7 +2874,7 @@ await connection.Receive( "", ""); // If we reach this point before the app exits, this means the flush finished early. - tcs.SetResult(null); + tcs.SetResult(); } } } @@ -3027,14 +3027,14 @@ public async Task OnStartingCallbacksAreCalledInLastInFirstOutOrder() var testContext = new TestServiceContext(LoggerFactory); var callOrder = new Stack(); - var onStartingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var onStartingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { context.Response.OnStarting(_ => { callOrder.Push(1); - onStartingTcs.SetResult(null); + onStartingTcs.SetResult(); return Task.CompletedTask; }, null); context.Response.OnStarting(_ => @@ -3078,14 +3078,14 @@ public async Task OnCompletedCallbacksAreCalledInLastInFirstOutOrder() var testContext = new TestServiceContext(LoggerFactory); var callOrder = new Stack(); - var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var onCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { context.Response.OnCompleted(_ => { callOrder.Push(1); - onCompletedTcs.SetResult(null); + onCompletedTcs.SetResult(); return Task.CompletedTask; }, null); context.Response.OnCompleted(_ => diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs index 75edff060105..bcf4dbf3ccd1 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs @@ -19,7 +19,7 @@ internal class InMemoryTransportConnection : TransportConnection private readonly ILogger _logger; private bool _isClosed; - private readonly TaskCompletionSource _waitForCloseTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _waitForCloseTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); public InMemoryTransportConnection(MemoryPool memoryPool, ILogger logger, PipeScheduler scheduler = null) { @@ -74,7 +74,7 @@ public void OnClosed() { state._connectionClosedTokenSource.Cancel(); - state._waitForCloseTcs.TrySetResult(null); + state._waitForCloseTcs.TrySetResult(); }, this, preferLocal: false); @@ -115,7 +115,7 @@ public ObservableDuplexPipe(IDuplexPipe duplexPipe) private class ObservablePipeReader : PipeReader { private readonly PipeReader _reader; - private readonly TaskCompletionSource _tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); public Task WaitForReadTask => _tcs.Task; @@ -164,9 +164,9 @@ public override bool TryRead(out ReadResult result) private class ObservableValueTask : IValueTaskSource { private readonly ValueTask _task; - private readonly TaskCompletionSource _tcs; + private readonly TaskCompletionSource _tcs; - public ObservableValueTask(ValueTask task, TaskCompletionSource tcs) + public ObservableValueTask(ValueTask task, TaskCompletionSource tcs) { _task = task; _tcs = tcs; @@ -198,7 +198,7 @@ public void OnCompleted(Action continuation, object state, short token, { _task.GetAwaiter().UnsafeOnCompleted(() => continuation(state)); - _tcs.TrySetResult(null); + _tcs.TrySetResult(); } } } diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/UpgradeTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/UpgradeTests.cs index cf36bb8a1512..30b8474ea252 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/UpgradeTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/UpgradeTests.cs @@ -112,7 +112,7 @@ await connection.Receive("HTTP/1.1 101 Switching Protocols", [Fact] public async Task UpgradeCannotBeCalledMultipleTimes() { - var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { var feature = context.Features.Get(); @@ -260,7 +260,7 @@ public async Task ThrowsWhenUpgradingNonUpgradableRequest() public async Task RejectsUpgradeWhenLimitReached() { const int limit = 10; - var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var upgradeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var serviceContext = new TestServiceContext(LoggerFactory); serviceContext.ConnectionManager = new ConnectionManager(serviceContext.Log, ResourceCounter.Quota(limit)); @@ -310,7 +310,7 @@ public async Task RejectsUpgradeWhenLimitReached() [Fact] public async Task DoesNotThrowOnFin() { - var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var appCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); await using (var server = new TestServer(async context => { @@ -320,7 +320,7 @@ public async Task DoesNotThrowOnFin() try { await duplexStream.CopyToAsync(Stream.Null); - appCompletedTcs.SetResult(null); + appCompletedTcs.SetResult(); } catch (Exception ex) { diff --git a/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs b/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs index fe3e2eb51d04..2e2857ba418a 100644 --- a/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs +++ b/src/Shared/Buffers.MemoryPool/DiagnosticMemoryPool.cs @@ -24,7 +24,7 @@ internal class DiagnosticMemoryPool : MemoryPool private readonly List _blockAccessExceptions; - private readonly TaskCompletionSource _allBlocksReturned; + private readonly TaskCompletionSource _allBlocksReturned; private int _totalBlocks; @@ -40,7 +40,7 @@ public DiagnosticMemoryPool(MemoryPool pool, bool allowLateReturn = false, _rentTracking = rentTracking; _blocks = new HashSet(); _syncObj = new object(); - _allBlocksReturned = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _allBlocksReturned = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); _blockAccessExceptions = new List(); } @@ -142,7 +142,7 @@ private void SetAllBlocksReturned() } else { - _allBlocksReturned.SetResult(null); + _allBlocksReturned.SetResult(); } } diff --git a/src/Shared/Http2cat/Http2Utilities.cs b/src/Shared/Http2cat/Http2Utilities.cs index b320850eaa1f..556249d7b724 100644 --- a/src/Shared/Http2cat/Http2Utilities.cs +++ b/src/Shared/Http2cat/Http2Utilities.cs @@ -229,7 +229,6 @@ await ExpectAsync(Http2FrameType.SETTINGS, public Task StartStreamAsync(int streamId, IEnumerable> headers, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var frame = new Http2Frame(); frame.PrepareHeaders(Http2HeadersFrameFlags.NONE, streamId); @@ -328,7 +327,6 @@ internal static void WriteHeader(Http2Frame frame, PipeWriter output) public Task SendHeadersWithPaddingAsync(int streamId, IEnumerable> headers, byte padLength, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var frame = new Http2Frame(); @@ -369,7 +367,6 @@ public Task SendHeadersWithPaddingAsync(int streamId, IEnumerable> headers, byte priority, int streamDependency, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var frame = new Http2Frame(); frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.PRIORITY, streamId); @@ -413,7 +410,6 @@ public Task SendHeadersWithPriorityAsync(int streamId, IEnumerable> headers, byte padLength, byte priority, int streamDependency, bool endStream) { var writableBuffer = _pair.Application.Output; - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var frame = new Http2Frame(); frame.PrepareHeaders(Http2HeadersFrameFlags.END_HEADERS | Http2HeadersFrameFlags.PADDED | Http2HeadersFrameFlags.PRIORITY, streamId); diff --git a/src/Shared/SyncPoint/SyncPoint.cs b/src/Shared/SyncPoint/SyncPoint.cs index ccf36d59dfc7..b668f2a8a169 100644 --- a/src/Shared/SyncPoint/SyncPoint.cs +++ b/src/Shared/SyncPoint/SyncPoint.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNetCore.Internal { public class SyncPoint { - private readonly TaskCompletionSource _atSyncPoint = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - private readonly TaskCompletionSource _continueFromSyncPoint = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _atSyncPoint = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _continueFromSyncPoint = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); /// /// Waits for the code-under-test to reach . @@ -20,7 +20,7 @@ public class SyncPoint /// /// Releases the code-under-test to continue past where it waited for . /// - public void Continue() => _continueFromSyncPoint.TrySetResult(null); + public void Continue() => _continueFromSyncPoint.TrySetResult(); /// /// Used by the code-under-test to wait for the test code to sync up. @@ -31,7 +31,7 @@ public class SyncPoint /// public Task WaitToContinue() { - _atSyncPoint.TrySetResult(null); + _atSyncPoint.TrySetResult(); return _continueFromSyncPoint.Task; } diff --git a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs index 46b0f3a67166..39f99f7ff092 100644 --- a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs +++ b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubConnectionTests.cs @@ -316,7 +316,7 @@ public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTra const string originalMessage = "SignalR"; var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); - var restartTcs = new TaskCompletionSource(); + var restartTcs = new TaskCompletionSource(); connection.Closed += async e => { try @@ -327,7 +327,7 @@ public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTra logger.LogInformation("Restarting connection"); await connection.StartAsync().OrTimeout(); logger.LogInformation("Restarted connection"); - restartTcs.SetResult(null); + restartTcs.SetResult(); } } catch (Exception ex) @@ -716,7 +716,7 @@ public async Task InvokeNonExistantClientMethodFromServer(string protocolName, H using (var server = await StartServer()) { var connection = CreateHubConnection(server.Url, path, transportType, protocol, LoggerFactory); - var closeTcs = new TaskCompletionSource(); + var closeTcs = new TaskCompletionSource(); connection.Closed += e => { if (e != null) @@ -725,7 +725,7 @@ public async Task InvokeNonExistantClientMethodFromServer(string protocolName, H } else { - closeTcs.SetResult(null); + closeTcs.SetResult(); } return Task.CompletedTask; }; @@ -1881,12 +1881,12 @@ bool ExpectedErrors(WriteContext writeContext) try { var echoMessage = "test"; - var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var reconnectedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.Reconnecting += _ => { - reconnectingTcs.SetResult(null); + reconnectingTcs.SetResult(); return Task.CompletedTask; }; @@ -1942,12 +1942,12 @@ bool ExpectedErrors(WriteContext writeContext) try { var echoMessage = "test"; - var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var reconnectedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.Reconnecting += _ => { - reconnectingTcs.SetResult(null); + reconnectingTcs.SetResult(); return Task.CompletedTask; }; @@ -2008,12 +2008,12 @@ bool ExpectedErrors(WriteContext writeContext) try { var echoMessage = "test"; - var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var reconnectingTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var reconnectedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.Reconnecting += _ => { - reconnectingTcs.SetResult(null); + reconnectingTcs.SetResult(); return Task.CompletedTask; }; diff --git a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubProtocolVersionTests.cs b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubProtocolVersionTests.cs index b7f3206313be..a7240053b8e3 100644 --- a/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubProtocolVersionTests.cs +++ b/src/SignalR/clients/csharp/Client/test/FunctionalTests/HubProtocolVersionTests.cs @@ -109,7 +109,7 @@ public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportT DefaultTransferFormat = TransferFormat.Text }), LoggerFactory); - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); var proxyConnectionFactory = new ProxyConnectionFactory(httpConnectionFactory); @@ -122,7 +122,7 @@ public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportT var connection = connectionBuilder.Build(); connection.On("NewProtocolMethodClient", () => { - tcs.SetResult(null); + tcs.SetResult(); }); try diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.ConnectionLifecycle.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.ConnectionLifecycle.cs index 3b1617178780..0a1f7e0052b7 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.ConnectionLifecycle.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HttpConnectionTests.ConnectionLifecycle.cs @@ -358,7 +358,7 @@ public async Task SSEWaitsForResponseToStart() { var httpHandler = new TestHttpMessageHandler(); - var connectResponseTcs = new TaskCompletionSource(); + var connectResponseTcs = new TaskCompletionSource(); httpHandler.OnGet("/?id=00000000-0000-0000-0000-000000000000", async (_, __) => { await connectResponseTcs.Task; @@ -374,7 +374,7 @@ await WithConnectionAsync( var startTask = connection.StartAsync(); Assert.False(connectResponseTcs.Task.IsCompleted); Assert.False(startTask.IsCompleted); - connectResponseTcs.TrySetResult(null); + connectResponseTcs.TrySetResult(); await startTask.OrTimeout(); }); } diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.ConnectionLifecycle.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.ConnectionLifecycle.cs index 77f380602e6d..0c1efc2e3d23 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.ConnectionLifecycle.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.ConnectionLifecycle.cs @@ -266,10 +266,10 @@ public async Task StatusIsDisconnectedInCloseEvent() var testConnection = new TestConnection(); await AsyncUsing(CreateHubConnection(testConnection), async connection => { - var closed = new TaskCompletionSource(); + var closed = new TaskCompletionSource(); connection.Closed += exception => { - closed.TrySetResult(null); + closed.TrySetResult(); Assert.Equal(HubConnectionState.Disconnected, connection.State); return Task.CompletedTask; }; @@ -358,12 +358,12 @@ await AsyncUsing(CreateHubConnection(testConnection), async connection => public async Task CompletingTheTransportSideMarksConnectionAsClosed() { var testConnection = new TestConnection(); - var closed = new TaskCompletionSource(); + var closed = new TaskCompletionSource(); await AsyncUsing(CreateHubConnection(testConnection), async connection => { connection.Closed += (e) => { - closed.TrySetResult(null); + closed.TrySetResult(); return Task.CompletedTask; }; await connection.StartAsync().OrTimeout(); @@ -383,13 +383,12 @@ await AsyncUsing(CreateHubConnection(testConnection), async connection => public async Task TransportCompletionWhileShuttingDownIsNoOp() { var testConnection = new TestConnection(); - var testConnectionClosed = new TaskCompletionSource(); - var connectionClosed = new TaskCompletionSource(); + var connectionClosed = new TaskCompletionSource(); await AsyncUsing(CreateHubConnection(testConnection), async connection => { connection.Closed += (e) => { - connectionClosed.TrySetResult(null); + connectionClosed.TrySetResult(); return Task.CompletedTask; }; @@ -423,12 +422,12 @@ await AsyncUsing(CreateHubConnection(testConnection), async connection => public async Task StopAsyncDuringUnderlyingConnectionCloseWaitsAndNoOps() { var testConnection = new TestConnection(); - var connectionClosed = new TaskCompletionSource(); + var connectionClosed = new TaskCompletionSource(); await AsyncUsing(CreateHubConnection(testConnection), async connection => { connection.Closed += (e) => { - connectionClosed.TrySetResult(null); + connectionClosed.TrySetResult(); return Task.CompletedTask; }; diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Reconnect.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Reconnect.cs index 9c46f0e0d638..225f2cac10f2 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Reconnect.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Reconnect.cs @@ -74,7 +74,7 @@ bool ExpectedErrors(WriteContext writeContext) writeContext.EventId.Name == "ReconnectingWithError"); } - var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (StartVerifiableLog(ExpectedErrors)) { @@ -188,7 +188,7 @@ bool ExpectedErrors(WriteContext writeContext) writeContext.EventId.Name == "ReconnectingWithError"); } - var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); using (StartVerifiableLog(ExpectedErrors)) { @@ -378,13 +378,11 @@ bool ExpectedErrors(WriteContext writeContext) writeContext.EventId.Name == "ReconnectingWithError"); } - var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - using (StartVerifiableLog(ExpectedErrors)) { var builder = new HubConnectionBuilder().WithLoggerFactory(LoggerFactory).WithUrl("http://example.com"); var testConnectionFactory = default(ReconnectingConnectionFactory); - + testConnectionFactory = new ReconnectingConnectionFactory(() => new TestConnection()); builder.Services.AddSingleton(testConnectionFactory); @@ -464,13 +462,11 @@ bool ExpectedErrors(WriteContext writeContext) writeContext.EventId.Name == "ShutdownWithError"); } - var failReconnectTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - using (StartVerifiableLog(ExpectedErrors)) { var builder = new HubConnectionBuilder().WithLoggerFactory(LoggerFactory).WithUrl("http://example.com"); var testConnectionFactory = default(ReconnectingConnectionFactory); - + testConnectionFactory = new ReconnectingConnectionFactory(() => new TestConnection()); builder.Services.AddSingleton(testConnectionFactory); @@ -647,7 +643,7 @@ bool ExpectedErrors(WriteContext writeContext) builder.Services.AddSingleton(testConnectionFactory); var retryContexts = new List(); - var secondRetryDelayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var secondRetryDelayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockReconnectPolicy = new Mock(); mockReconnectPolicy.Setup(p => p.NextRetryDelay(It.IsAny())).Returns(context => { @@ -655,7 +651,7 @@ bool ExpectedErrors(WriteContext writeContext) if (retryContexts.Count == 2) { - secondRetryDelayTcs.SetResult(null); + secondRetryDelayTcs.SetResult(); } return TimeSpan.Zero; @@ -754,7 +750,7 @@ bool ExpectedErrors(WriteContext writeContext) builder.Services.AddSingleton(testConnectionFactory); var retryContexts = new List(); - var secondRetryDelayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var secondRetryDelayTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var mockReconnectPolicy = new Mock(); mockReconnectPolicy.Setup(p => p.NextRetryDelay(It.IsAny())).Returns(context => { @@ -762,7 +758,7 @@ bool ExpectedErrors(WriteContext writeContext) if (retryContexts.Count == 2) { - secondRetryDelayTcs.SetResult(null); + secondRetryDelayTcs.SetResult(); } return TimeSpan.Zero; @@ -869,7 +865,7 @@ bool ExpectedErrors(WriteContext writeContext) using (StartVerifiableLog(ExpectedErrors)) { var builder = new HubConnectionBuilder().WithLoggerFactory(LoggerFactory).WithUrl("http://example.com"); - var connectionStartTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var connectionStartTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); async Task OnTestConnectionStart() { @@ -879,7 +875,7 @@ async Task OnTestConnectionStart() } finally { - connectionStartTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + connectionStartTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } } @@ -921,7 +917,7 @@ async Task OnTestConnectionStart() }; // Allow the first connection to start successfully. - connectionStartTcs.SetResult(null); + connectionStartTcs.SetResult(); await hubConnection.StartAsync().OrTimeout(); var firstException = new Exception(); @@ -935,7 +931,7 @@ async Task OnTestConnectionStart() var secondException = new Exception(); var stopTask = hubConnection.StopAsync(); - connectionStartTcs.SetResult(null); + connectionStartTcs.SetResult(); Assert.IsType(await closedErrorTcs.Task.OrTimeout()); Assert.Single(retryContexts); diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.cs index 1a8d99e7842b..618d6f14a92b 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.cs @@ -84,18 +84,18 @@ public async Task StopAsyncCanBeCalledFromOnHandler() var connection = new TestConnection(); var hubConnection = CreateHubConnection(connection, loggerFactory: LoggerFactory); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); hubConnection.On("method", async () => { await hubConnection.StopAsync().OrTimeout(); - tcs.SetResult(null); + tcs.SetResult(); }); await hubConnection.StartAsync().OrTimeout(); await connection.ReceiveJsonMessage(new { type = HubProtocolConstants.InvocationMessageType, target= "method", arguments = new object[] { } }).OrTimeout(); - Assert.Null(await tcs.Task.OrTimeout()); + await tcs.Task.OrTimeout(); } [Fact] @@ -104,11 +104,11 @@ public async Task StopAsyncDoesNotWaitForOnHandlers() var connection = new TestConnection(); var hubConnection = CreateHubConnection(connection, loggerFactory: LoggerFactory); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); - var methodCalledTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var methodCalledTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); hubConnection.On("method", async () => { - methodCalledTcs.SetResult(null); + methodCalledTcs.SetResult(); await tcs.Task; }); @@ -119,7 +119,7 @@ public async Task StopAsyncDoesNotWaitForOnHandlers() await methodCalledTcs.Task.OrTimeout(); await hubConnection.StopAsync().OrTimeout(); - tcs.SetResult(null); + tcs.SetResult(); } [Fact] @@ -559,7 +559,7 @@ public async Task CanAwaitInvokeFromOnHandlerWithServerClosingConnection() var hubConnection = CreateHubConnection(connection, loggerFactory: LoggerFactory); await hubConnection.StartAsync().OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); hubConnection.On("Echo", async msg => { try @@ -573,13 +573,13 @@ public async Task CanAwaitInvokeFromOnHandlerWithServerClosingConnection() return; } - tcs.SetResult(null); + tcs.SetResult(); }); - var closedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var closedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); hubConnection.Closed += _ => { - closedTcs.SetResult(null); + closedTcs.SetResult(); return Task.CompletedTask; }; diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/LongPollingTransportTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/LongPollingTransportTests.cs index 0d985d69c0bf..4274997b0459 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/LongPollingTransportTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/LongPollingTransportTests.cs @@ -222,7 +222,7 @@ async Task ReadAsync() [Fact] public async Task StopTransportWhenConnectionAlreadyStoppedOnServer() { - var pollRequestTcs = new TaskCompletionSource(); + var pollRequestTcs = new TaskCompletionSource(); var mockHttpHandler = new Mock(); var firstPoll = true; @@ -259,7 +259,7 @@ public async Task StopTransportWhenConnectionAlreadyStoppedOnServer() var stopTask = longPollingTransport.StopAsync(); - pollRequestTcs.SetResult(null); + pollRequestTcs.SetResult(); await stopTask.OrTimeout(); } @@ -520,7 +520,7 @@ public async Task LongPollingTransportSendsDeleteAfterPollEnds() { var sentRequests = new List(); var pollTcs = new TaskCompletionSource(); - var deleteTcs = new TaskCompletionSource(); + var deleteTcs = new TaskCompletionSource(); var firstPoll = true; var mockHttpHandler = new Mock(); @@ -552,7 +552,7 @@ public async Task LongPollingTransportSendsDeleteAfterPollEnds() // The poll task should have been completed Assert.True(pollTcs.Task.IsCompleted); - deleteTcs.TrySetResult(null); + deleteTcs.TrySetResult(); return ResponseUtils.CreateResponse(HttpStatusCode.Accepted); } @@ -632,7 +632,7 @@ public async Task LongPollingTransportThrowsForInvalidTransferFormat(TransferFor public async Task LongPollingTransportRePollsIfRequestCanceled() { var numPolls = 0; - var completionTcs = new TaskCompletionSource(); + var completionTcs = new TaskCompletionSource(); var mockHttpHandler = new Mock(); mockHttpHandler.Protected() @@ -652,7 +652,7 @@ public async Task LongPollingTransportRePollsIfRequestCanceled() throw new OperationCanceledException(); } - completionTcs.SetResult(null); + completionTcs.SetResult(); return ResponseUtils.CreateResponse(HttpStatusCode.OK); }); diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/ServerSentEventsTransportTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/ServerSentEventsTransportTests.cs index ffbe81a8e762..5ea3b18515a9 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/ServerSentEventsTransportTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/ServerSentEventsTransportTests.cs @@ -25,8 +25,8 @@ public class ServerSentEventsTransportTests : VerifiableLoggedTest [Fact] public async Task CanStartStopSSETransport() { - var eventStreamTcs = new TaskCompletionSource(); - var copyToAsyncTcs = new TaskCompletionSource(); + var eventStreamTcs = new TaskCompletionSource(); + var copyToAsyncTcs = new TaskCompletionSource(); var mockHttpHandler = new Mock(); mockHttpHandler.Protected() @@ -35,7 +35,7 @@ public async Task CanStartStopSSETransport() { await Task.Yield(); // Receive loop started - allow stopping the transport - eventStreamTcs.SetResult(null); + eventStreamTcs.SetResult(); // returns unfinished task to block pipelines var mockStream = new Mock(); @@ -62,7 +62,7 @@ await sseTransport.StartAsync( } finally { - copyToAsyncTcs.SetResult(0); + copyToAsyncTcs.SetResult(); } } @@ -171,7 +171,7 @@ bool ExpectedErrors(WriteContext writeContext) writeContext.EventId.Name == "ErrorSending"; } - var eventStreamTcs = new TaskCompletionSource(); + var eventStreamTcs = new TaskCompletionSource(); var readTcs = new TaskCompletionSource(); var mockHttpHandler = new Mock(); @@ -184,7 +184,7 @@ bool ExpectedErrors(WriteContext writeContext) if (request.Headers.Accept?.Contains(new MediaTypeWithQualityHeaderValue("text/event-stream")) == true) { // Receive loop started - allow stopping the transport - eventStreamTcs.SetResult(null); + eventStreamTcs.SetResult(); // returns unfinished task to block pipelines var mockStream = new Mock(); @@ -226,7 +226,7 @@ await sseTransport.StartAsync( [Fact] public async Task SSETransportStopsIfChannelClosed() { - var eventStreamTcs = new TaskCompletionSource(); + var eventStreamTcs = new TaskCompletionSource(); var readTcs = new TaskCompletionSource(); var mockHttpHandler = new Mock(); @@ -237,7 +237,7 @@ public async Task SSETransportStopsIfChannelClosed() await Task.Yield(); // Receive loop started - allow stopping the transport - eventStreamTcs.SetResult(null); + eventStreamTcs.SetResult(); // returns unfinished task to block pipelines var mockStream = new Mock(); @@ -299,8 +299,8 @@ await sseTransport.StartAsync( [Fact] public async Task SSETransportCancelsSendOnStop() { - var eventStreamTcs = new TaskCompletionSource(); - var readTcs = new TaskCompletionSource(); + var eventStreamTcs = new TaskCompletionSource(); + var readTcs = new TaskCompletionSource(); var sendSyncPoint = new SyncPoint(); var mockHttpHandler = new Mock(); @@ -313,7 +313,7 @@ public async Task SSETransportCancelsSendOnStop() if (request.Headers.Accept?.Contains(new MediaTypeWithQualityHeaderValue("text/event-stream")) == true) { // Receive loop started - allow stopping the transport - eventStreamTcs.SetResult(null); + eventStreamTcs.SetResult(); // returns unfinished task to block pipelines var mockStream = new Mock(); @@ -351,7 +351,7 @@ await sseTransport.StartAsync( var stopTask = sseTransport.StopAsync(); - readTcs.SetResult(null); + readTcs.SetResult(); sendSyncPoint.Continue(); await stopTask; diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/TestConnection.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/TestConnection.cs index 0da16cf1607f..6de99c1c96e0 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/TestConnection.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/TestConnection.cs @@ -22,8 +22,8 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests internal class TestConnection : ConnectionContext, IConnectionInherentKeepAliveFeature { private readonly bool _autoHandshake; - private readonly TaskCompletionSource _started = new TaskCompletionSource(); - private readonly TaskCompletionSource _disposed = new TaskCompletionSource(); + private readonly TaskCompletionSource _started = new TaskCompletionSource(); + private readonly TaskCompletionSource _disposed = new TaskCompletionSource(); private int _disposeCount = 0; public Task Started => _started.Task; @@ -65,7 +65,7 @@ public TestConnection(Func onStart = null, Func onDispose = null, bo public async ValueTask StartAsync() { - _started.TrySetResult(null); + _started.TrySetResult(); await _onStart(); @@ -204,7 +204,7 @@ public void CompleteFromTransport(Exception ex = null) private async ValueTask DisposeCoreAsync(Exception ex = null) { Interlocked.Increment(ref _disposeCount); - _disposed.TrySetResult(null); + _disposed.TrySetResult(); await _onDispose(); // Simulate HttpConnection's behavior by Completing the Transport pipe. diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/TestHttpMessageHandler.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/TestHttpMessageHandler.cs index 8144d9d574e3..cd90702e29be 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/TestHttpMessageHandler.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/TestHttpMessageHandler.cs @@ -111,8 +111,8 @@ public static TestHttpMessageHandler CreateDefault() var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, deleteCts.Token); // Just block until canceled - var tcs = new TaskCompletionSource(); - using (cts.Token.Register(() => tcs.TrySetResult(null))) + var tcs = new TaskCompletionSource(); + using (cts.Token.Register(() => tcs.TrySetResult())) { await tcs.Task; } diff --git a/src/SignalR/clients/csharp/Client/test/UnitTests/TimerAwaitableTests.cs b/src/SignalR/clients/csharp/Client/test/UnitTests/TimerAwaitableTests.cs index 2d61118186a3..e0e7248df44a 100644 --- a/src/SignalR/clients/csharp/Client/test/UnitTests/TimerAwaitableTests.cs +++ b/src/SignalR/clients/csharp/Client/test/UnitTests/TimerAwaitableTests.cs @@ -16,7 +16,7 @@ public class TimerAwaitableTests [QuarantinedTest] public async Task FinalizerRunsIfTimerAwaitableReferencesObject() { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); UseTimerAwaitableAndUnref(tcs); GC.Collect(); @@ -27,7 +27,7 @@ public async Task FinalizerRunsIfTimerAwaitableReferencesObject() } [MethodImpl(MethodImplOptions.NoInlining)] - private void UseTimerAwaitableAndUnref(TaskCompletionSource tcs) + private void UseTimerAwaitableAndUnref(TaskCompletionSource tcs) { _ = new ObjectWithTimerAwaitable(tcs).Start(); } @@ -38,9 +38,9 @@ private void UseTimerAwaitableAndUnref(TaskCompletionSource tcs) public class ObjectWithTimerAwaitable { private readonly TimerAwaitable _timer; - private readonly TaskCompletionSource _tcs; + private readonly TaskCompletionSource _tcs; - public ObjectWithTimerAwaitable(TaskCompletionSource tcs) + public ObjectWithTimerAwaitable(TaskCompletionSource tcs) { _tcs = tcs; _timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)); @@ -59,7 +59,7 @@ public async Task Start() ~ObjectWithTimerAwaitable() { - _tcs.TrySetResult(null); + _tcs.TrySetResult(); } } } diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs index c9495d7156c4..783bcf07bf91 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionContext.cs @@ -50,7 +50,7 @@ internal class HttpConnectionContext : ConnectionContext, // This tcs exists so that multiple calls to DisposeAsync all wait asynchronously // on the same task - private readonly TaskCompletionSource _disposeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _disposeTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); /// /// Creates the DefaultConnectionContext without Pipes to avoid upfront allocations. @@ -330,7 +330,7 @@ private async Task WaitOnTasks(Task applicationTask, Task transportTask, bool cl } // Notify all waiters that we're done disposing - _disposeTcs.TrySetResult(null); + _disposeTcs.TrySetResult(); } catch (OperationCanceledException) { diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs index 969d4a593521..7f6477cab072 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs @@ -196,7 +196,7 @@ private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connecti } // Create a new Tcs every poll to keep track of the poll finishing, so we can properly wait on previous polls - var currentRequestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var currentRequestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); if (!connection.TryActivateLongPollingConnection( connectionDelegate, context, options.LongPolling.PollTimeout, @@ -254,7 +254,7 @@ private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connecti { // Artificial task queue // This will cause incoming polls to wait until the previous poll has finished updating internal state info - currentRequestTcs.TrySetResult(null); + currentRequestTcs.TrySetResult(); } } } diff --git a/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs b/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs index 5f084a232f90..22e5d5d6a22e 100644 --- a/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs +++ b/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs @@ -1385,7 +1385,7 @@ public async Task MultipleRequestsToActiveConnectionId409ForLongPolling() // Manually control PreviousPollTask instead of using a real PreviousPollTask, because a real // PreviousPollTask might complete too early when the second request cancels it. - var lastPollTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var lastPollTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.PreviousPollTask = lastPollTcs.Task; request1 = dispatcher.ExecuteAsync(context1, options, app); @@ -1394,7 +1394,7 @@ public async Task MultipleRequestsToActiveConnectionId409ForLongPolling() Assert.False(request1.IsCompleted); Assert.False(request2.IsCompleted); - lastPollTcs.SetResult(null); + lastPollTcs.SetResult(); var completedTask = await Task.WhenAny(request1, request2).OrTimeout(); @@ -1977,18 +1977,18 @@ public async Task PollCanReceiveFinalMessageAfterAppCompletes() var connection = manager.CreateConnection(); connection.TransportType = transportType; - var waitForMessageTcs1 = new TaskCompletionSource(); - var messageTcs1 = new TaskCompletionSource(); - var waitForMessageTcs2 = new TaskCompletionSource(); - var messageTcs2 = new TaskCompletionSource(); + var waitForMessageTcs1 = new TaskCompletionSource(); + var messageTcs1 = new TaskCompletionSource(); + var waitForMessageTcs2 = new TaskCompletionSource(); + var messageTcs2 = new TaskCompletionSource(); ConnectionDelegate connectionDelegate = async c => { await waitForMessageTcs1.Task.OrTimeout(); await c.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Message1")).OrTimeout(); - messageTcs1.TrySetResult(null); + messageTcs1.TrySetResult(); await waitForMessageTcs2.Task.OrTimeout(); await c.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Message2")).OrTimeout(); - messageTcs2.TrySetResult(null); + messageTcs2.TrySetResult(); }; { var options = new HttpConnectionDispatcherOptions(); @@ -1996,7 +1996,7 @@ public async Task PollCanReceiveFinalMessageAfterAppCompletes() await dispatcher.ExecuteAsync(context, options, connectionDelegate).OrTimeout(); // second poll should have data - waitForMessageTcs1.SetResult(null); + waitForMessageTcs1.SetResult(); await messageTcs1.Task.OrTimeout(); var ms = new MemoryStream(); @@ -2005,7 +2005,7 @@ public async Task PollCanReceiveFinalMessageAfterAppCompletes() await dispatcher.ExecuteAsync(context, options, connectionDelegate).OrTimeout(); Assert.Equal("Message1", Encoding.UTF8.GetString(ms.ToArray())); - waitForMessageTcs2.SetResult(null); + waitForMessageTcs2.SetResult(); await messageTcs2.Task.OrTimeout(); context = MakeRequest("/foo", connection); @@ -2372,7 +2372,7 @@ public class NeverEndingConnectionHandler : ConnectionHandler { public override Task OnConnectedAsync(ConnectionContext connection) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); return tcs.Task; } } @@ -2438,13 +2438,13 @@ public override async Task OnConnectedAsync(ConnectionContext connection) public class TestConnectionHandler : ConnectionHandler { - private TaskCompletionSource _startedTcs = new TaskCompletionSource(); + private TaskCompletionSource _startedTcs = new TaskCompletionSource(); public Task Started => _startedTcs.Task; public override async Task OnConnectedAsync(ConnectionContext connection) { - _startedTcs.TrySetResult(null); + _startedTcs.TrySetResult(); while (true) { diff --git a/src/SignalR/common/Http.Connections/test/HttpConnectionManagerTests.cs b/src/SignalR/common/Http.Connections/test/HttpConnectionManagerTests.cs index dcf8dfefa977..35528c76267e 100644 --- a/src/SignalR/common/Http.Connections/test/HttpConnectionManagerTests.cs +++ b/src/SignalR/common/Http.Connections/test/HttpConnectionManagerTests.cs @@ -94,11 +94,6 @@ public async Task DisposingConnectionsClosesBothSidesOfThePipe(ConnectionStates connection.TransportTask = Task.CompletedTask; } - var applicationInputTcs = new TaskCompletionSource(); - var applicationOutputTcs = new TaskCompletionSource(); - var transportInputTcs = new TaskCompletionSource(); - var transportOutputTcs = new TaskCompletionSource(); - try { await connection.DisposeAsync(closeGracefully).OrTimeout(); @@ -269,7 +264,7 @@ public async Task DisposingConnectionMultipleTimesWaitsOnConnectionClose() { var connectionManager = CreateConnectionManager(LoggerFactory); var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.ApplicationTask = tcs.Task; connection.TransportTask = tcs.Task; @@ -279,7 +274,7 @@ public async Task DisposingConnectionMultipleTimesWaitsOnConnectionClose() Assert.False(firstTask.IsCompleted); Assert.False(secondTask.IsCompleted); - tcs.TrySetResult(null); + tcs.TrySetResult(); await Task.WhenAll(firstTask, secondTask).OrTimeout(); } @@ -292,7 +287,7 @@ public async Task DisposingConnectionMultipleGetsExceptionFromTransportOrApp() { var connectionManager = CreateConnectionManager(LoggerFactory); var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.ApplicationTask = tcs.Task; connection.TransportTask = tcs.Task; @@ -319,7 +314,7 @@ public async Task DisposingConnectionMultipleGetsCancellation() { var connectionManager = CreateConnectionManager(LoggerFactory); var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection.ApplicationTask = tcs.Task; connection.TransportTask = tcs.Task; @@ -376,7 +371,6 @@ public async Task ApplicationLifetimeIsHookedUp() { var appLifetime = new TestApplicationLifetime(); var connectionManager = CreateConnectionManager(LoggerFactory, appLifetime); - var tcs = new TaskCompletionSource(); appLifetime.Start(); @@ -398,7 +392,6 @@ public async Task ApplicationLifetimeCanStartBeforeHttpConnectionManagerInitiali appLifetime.Start(); var connectionManager = CreateConnectionManager(LoggerFactory, appLifetime); - var tcs = new TaskCompletionSource(); var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default); diff --git a/src/SignalR/common/Http.Connections/test/TestWebSocketConnectionFeature.cs b/src/SignalR/common/Http.Connections/test/TestWebSocketConnectionFeature.cs index 9bbb6894dbe4..b84a6b71069e 100644 --- a/src/SignalR/common/Http.Connections/test/TestWebSocketConnectionFeature.cs +++ b/src/SignalR/common/Http.Connections/test/TestWebSocketConnectionFeature.cs @@ -20,7 +20,7 @@ public TestWebSocketConnectionFeature(SyncPoint sync) } private readonly SyncPoint _sync; - private readonly TaskCompletionSource _accepted = new TaskCompletionSource(); + private readonly TaskCompletionSource _accepted = new TaskCompletionSource(); public bool IsWebSocketRequest => true; @@ -43,7 +43,7 @@ public Task AcceptAsync(WebSocketAcceptContext context) Client = clientSocket; SubProtocol = context.SubProtocol; - _accepted.TrySetResult(null); + _accepted.TrySetResult(); return Task.FromResult(serverSocket); } diff --git a/src/SignalR/common/testassets/Tests.Utils/CancellationTokenExtensions.cs b/src/SignalR/common/testassets/Tests.Utils/CancellationTokenExtensions.cs index fadb9626bf9d..206d347aeed7 100644 --- a/src/SignalR/common/testassets/Tests.Utils/CancellationTokenExtensions.cs +++ b/src/SignalR/common/testassets/Tests.Utils/CancellationTokenExtensions.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; @@ -10,10 +10,10 @@ public static class CancellationTokenExtensions { public static Task WaitForCancellationAsync(this CancellationToken token) { - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); token.Register((t) => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); return tcs.Task; } diff --git a/src/SignalR/perf/Microbenchmarks/DefaultHubDispatcherBenchmark.cs b/src/SignalR/perf/Microbenchmarks/DefaultHubDispatcherBenchmark.cs index 4a0e67e0fb3a..6850989e3da7 100644 --- a/src/SignalR/perf/Microbenchmarks/DefaultHubDispatcherBenchmark.cs +++ b/src/SignalR/perf/Microbenchmarks/DefaultHubDispatcherBenchmark.cs @@ -83,7 +83,7 @@ public ReadOnlyMemory GetMessageBytes(HubMessage message) public class NoErrorHubConnectionContext : HubConnectionContext { - public TaskCompletionSource ReceivedCompleted = new TaskCompletionSource(); + public TaskCompletionSource ReceivedCompleted = new TaskCompletionSource(); public NoErrorHubConnectionContext(ConnectionContext connectionContext, HubConnectionContextOptions contextOptions, ILoggerFactory loggerFactory) : base(connectionContext, contextOptions, loggerFactory) @@ -94,7 +94,7 @@ public override ValueTask WriteAsync(HubMessage message, CancellationToken cance { if (message is CompletionMessage completionMessage) { - ReceivedCompleted.TrySetResult(null); + ReceivedCompleted.TrySetResult(); if (!string.IsNullOrEmpty(completionMessage.Error)) { @@ -264,7 +264,7 @@ public async Task StreamChannelReaderCount_Zero() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamChannelReaderCount", new object[] { 0 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -273,7 +273,7 @@ public async Task StreamIAsyncEnumerableCount_Zero() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCount", new object[] { 0 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -282,7 +282,7 @@ public async Task StreamIAsyncEnumerableCompletedTaskCount_Zero() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCountCompletedTask", new object[] { 0 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -291,7 +291,7 @@ public async Task StreamChannelReaderCount_One() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamChannelReaderCount", new object[] { 1 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -300,7 +300,7 @@ public async Task StreamIAsyncEnumerableCount_One() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCount", new object[] { 1 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -309,7 +309,7 @@ public async Task StreamIAsyncEnumerableCompletedTaskCount_One() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCountCompletedTask", new object[] { 1 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -318,7 +318,7 @@ public async Task StreamChannelReaderCount_Thousand() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamChannelReaderCount", new object[] { 1000 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -327,7 +327,7 @@ public async Task StreamIAsyncEnumerableCount_Thousand() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCount", new object[] { 1000 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -336,7 +336,7 @@ public async Task StreamIAsyncEnumerableCompletedTaskCount_Thousand() await _dispatcher.DispatchMessageAsync(_connectionContext, new StreamInvocationMessage("123", "StreamIAsyncEnumerableCountCompletedTask", new object[] { 1000 })); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -347,7 +347,7 @@ public async Task UploadStream_One() await _dispatcher.DispatchMessageAsync(_connectionContext, CompletionMessage.Empty("1")); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -358,7 +358,7 @@ public async Task UploadStreamIAsyncEnumerable_One() await _dispatcher.DispatchMessageAsync(_connectionContext, CompletionMessage.Empty("1")); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -372,7 +372,7 @@ public async Task UploadStream_Thousand() await _dispatcher.DispatchMessageAsync(_connectionContext, CompletionMessage.Empty("1")); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } [Benchmark] @@ -386,7 +386,7 @@ public async Task UploadStreamIAsyncEnumerable_Thousand() await _dispatcher.DispatchMessageAsync(_connectionContext, CompletionMessage.Empty("1")); await (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted.Task; - (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); + (_connectionContext as NoErrorHubConnectionContext).ReceivedCompleted = new TaskCompletionSource(); } } } diff --git a/src/SignalR/samples/JwtClientSample/Program.cs b/src/SignalR/samples/JwtClientSample/Program.cs index 0cf4ac17eddb..67bf5750ee6d 100644 --- a/src/SignalR/samples/JwtClientSample/Program.cs +++ b/src/SignalR/samples/JwtClientSample/Program.cs @@ -39,10 +39,10 @@ private async Task RunConnection(HttpTransportType transportType) }) .Build(); - var closedTcs = new TaskCompletionSource(); + var closedTcs = new TaskCompletionSource(); hubConnection.Closed += e => { - closedTcs.SetResult(null); + closedTcs.SetResult(); return Task.CompletedTask; }; diff --git a/src/SignalR/server/Core/src/HubConnectionContext.cs b/src/SignalR/server/Core/src/HubConnectionContext.cs index fcd704c428ea..8611e54bae6c 100644 --- a/src/SignalR/server/Core/src/HubConnectionContext.cs +++ b/src/SignalR/server/Core/src/HubConnectionContext.cs @@ -31,7 +31,7 @@ public class HubConnectionContext private readonly ConnectionContext _connectionContext; private readonly ILogger _logger; private readonly CancellationTokenSource _connectionAbortedTokenSource = new CancellationTokenSource(); - private readonly TaskCompletionSource _abortCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource _abortCompletedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); private readonly long _keepAliveInterval; private readonly long _clientTimeoutInterval; private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1); @@ -640,7 +640,7 @@ static async Task InnerAbortConnection(HubConnectionContext connection) { // Communicate the fact that we're finished triggering abort callbacks // HubOnDisconnectedAsync is waiting on this to complete the Pipe - connection._abortCompletedTcs.TrySetResult(null); + connection._abortCompletedTcs.TrySetResult(); } finally { diff --git a/src/SignalR/server/SignalR/test/DefaultHubLifetimeManagerTests.cs b/src/SignalR/server/SignalR/test/DefaultHubLifetimeManagerTests.cs index ee312dbf3e66..e1f0240c7df9 100644 --- a/src/SignalR/server/SignalR/test/DefaultHubLifetimeManagerTests.cs +++ b/src/SignalR/server/SignalR/test/DefaultHubLifetimeManagerTests.cs @@ -39,10 +39,10 @@ public async Task SendAllAsyncWillCancelWithToken() Assert.Equal("Hello", message.Target); Assert.Single(message.Arguments); Assert.Equal("World", (string)message.Arguments[0]); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection2.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); Assert.False(connection1.ConnectionAborted.IsCancellationRequested); @@ -65,10 +65,10 @@ public async Task SendAllExceptAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection2.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); Assert.False(connection1.ConnectionAborted.IsCancellationRequested); @@ -89,10 +89,10 @@ public async Task SendConnectionAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection1.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); } @@ -111,10 +111,10 @@ public async Task SendConnectionsAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection1.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); } @@ -134,10 +134,10 @@ public async Task SendGroupAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection1.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); } @@ -161,10 +161,10 @@ public async Task SendGroupExceptAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection2.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); Assert.False(connection1.ConnectionAborted.IsCancellationRequested); @@ -186,10 +186,10 @@ public async Task SendGroupsAsyncWillCancelWithToken() Assert.False(sendTask.IsCompleted); cts.Cancel(); await sendTask.OrTimeout(); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection1.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); } @@ -215,10 +215,10 @@ public async Task SendUserAsyncWillCancelWithToken() Assert.Equal("Hello", message.Target); Assert.Single(message.Arguments); Assert.Equal("World", (string)message.Arguments[0]); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection2.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); Assert.False(connection1.ConnectionAborted.IsCancellationRequested); @@ -245,10 +245,10 @@ public async Task SendUsersAsyncWillCancelWithToken() Assert.Equal("Hello", message.Target); Assert.Single(message.Arguments); Assert.Equal("World", (string)message.Arguments[0]); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); connection2.ConnectionAborted.Register(t => { - ((TaskCompletionSource)t).SetResult(null); + ((TaskCompletionSource)t).SetResult(); }, tcs); await tcs.Task.OrTimeout(); Assert.False(connection1.ConnectionAborted.IsCancellationRequested); diff --git a/src/SignalR/server/SignalR/test/EndToEndTests.cs b/src/SignalR/server/SignalR/test/EndToEndTests.cs index 675d939a3af6..7461b2e90ebe 100644 --- a/src/SignalR/server/SignalR/test/EndToEndTests.cs +++ b/src/SignalR/server/SignalR/test/EndToEndTests.cs @@ -550,7 +550,7 @@ private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTrans .Build(); try { - var closeTcs = new TaskCompletionSource(); + var closeTcs = new TaskCompletionSource(); connection.Closed += e => { if (e != null) @@ -559,7 +559,7 @@ private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTrans } else { - closeTcs.SetResult(null); + closeTcs.SetResult(); } return Task.CompletedTask; }; diff --git a/src/SignalR/server/SignalR/test/HubConnectionHandlerTestUtils/Hubs.cs b/src/SignalR/server/SignalR/test/HubConnectionHandlerTestUtils/Hubs.cs index a33cb809d034..c9e790c11aa7 100644 --- a/src/SignalR/server/SignalR/test/HubConnectionHandlerTestUtils/Hubs.cs +++ b/src/SignalR/server/SignalR/test/HubConnectionHandlerTestUtils/Hubs.cs @@ -510,7 +510,7 @@ public class OnConnectedThrowsHub : Hub { public override Task OnConnectedAsync() { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); tcs.SetException(new InvalidOperationException("Hub OnConnected failed.")); return tcs.Task; } @@ -520,7 +520,7 @@ public class OnDisconnectedThrowsHub : TestHub { public override Task OnDisconnectedAsync(Exception exception) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); tcs.SetException(new InvalidOperationException("Hub OnDisconnected failed.")); return tcs.Task; } diff --git a/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs b/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs index ca7b1093f39a..962d32bc7cb2 100644 --- a/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs +++ b/src/SignalR/server/SignalR/test/HubConnectionHandlerTests.cs @@ -2823,13 +2823,13 @@ public async Task ReceivingMessagesPreventsConnectionTimeoutFromOccuring() internal class PipeReaderWrapper : PipeReader { private readonly PipeReader _originalPipeReader; - private TaskCompletionSource _waitForRead; + private TaskCompletionSource _waitForRead; private object _lock = new object(); public PipeReaderWrapper(PipeReader pipeReader) { _originalPipeReader = pipeReader; - _waitForRead = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _waitForRead = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } public override void AdvanceTo(SequencePosition consumed) => @@ -2848,7 +2848,7 @@ public override async ValueTask ReadAsync(CancellationToken cancella { lock (_lock) { - _waitForRead.SetResult(null); + _waitForRead.SetResult(); } try @@ -2859,7 +2859,7 @@ public override async ValueTask ReadAsync(CancellationToken cancella { lock (_lock) { - _waitForRead = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + _waitForRead = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } } } @@ -4011,8 +4011,8 @@ private class CustomHubActivator : IHubActivator where THub : Hub { public int ReleaseCount; private IServiceProvider _serviceProvider; - public TaskCompletionSource ReleaseTask = new TaskCompletionSource(); - public TaskCompletionSource CreateTask = new TaskCompletionSource(); + public TaskCompletionSource ReleaseTask = new TaskCompletionSource(); + public TaskCompletionSource CreateTask = new TaskCompletionSource(); public CustomHubActivator(IServiceProvider serviceProvider) { @@ -4021,9 +4021,9 @@ public CustomHubActivator(IServiceProvider serviceProvider) public THub Create() { - ReleaseTask = new TaskCompletionSource(); + ReleaseTask = new TaskCompletionSource(); var hub = new DefaultHubActivator(_serviceProvider).Create(); - CreateTask.TrySetResult(null); + CreateTask.TrySetResult(); return hub; } @@ -4031,8 +4031,8 @@ public void Release(THub hub) { ReleaseCount++; hub.Dispose(); - ReleaseTask.TrySetResult(null); - CreateTask = new TaskCompletionSource(); + ReleaseTask.TrySetResult(); + CreateTask = new TaskCompletionSource(); } } diff --git a/src/SignalR/server/SignalR/test/Internal/TypedClientBuilderTests.cs b/src/SignalR/server/SignalR/test/Internal/TypedClientBuilderTests.cs index f88820cb78cf..83b601d6f48e 100644 --- a/src/SignalR/server/SignalR/test/Internal/TypedClientBuilderTests.cs +++ b/src/SignalR/server/SignalR/test/Internal/TypedClientBuilderTests.cs @@ -236,7 +236,7 @@ private class MockProxy : IClientProxy public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); Sends.Add(new SendContext(method, args, cancellationToken, tcs)); @@ -246,13 +246,13 @@ public Task SendCoreAsync(string method, object[] args, CancellationToken cancel private struct SendContext { - private TaskCompletionSource _tcs; + private TaskCompletionSource _tcs; public string Method { get; } public object[] Arguments { get; } public CancellationToken CancellationToken { get; } - public SendContext(string method, object[] arguments, CancellationToken cancellationToken, TaskCompletionSource tcs) : this() + public SendContext(string method, object[] arguments, CancellationToken cancellationToken, TaskCompletionSource tcs) : this() { Method = method; Arguments = arguments; @@ -262,7 +262,7 @@ public SendContext(string method, object[] arguments, CancellationToken cancella public void Complete() { - _tcs.TrySetResult(null); + _tcs.TrySetResult(); } } } diff --git a/src/SignalR/server/StackExchangeRedis/src/Internal/AckHandler.cs b/src/SignalR/server/StackExchangeRedis/src/Internal/AckHandler.cs index 863fcdcb531f..1a9d264097d9 100644 --- a/src/SignalR/server/StackExchangeRedis/src/Internal/AckHandler.cs +++ b/src/SignalR/server/StackExchangeRedis/src/Internal/AckHandler.cs @@ -58,7 +58,7 @@ public void TriggerAck(int id) { if (_acks.TryRemove(id, out var ack)) { - ack.Tcs.TrySetResult(null); + ack.Tcs.TrySetResult(); } } @@ -104,14 +104,14 @@ public void Dispose() private class AckInfo { - public TaskCompletionSource Tcs { get; private set; } + public TaskCompletionSource Tcs { get; private set; } public DateTime Created { get; private set; } public AckInfo() { Created = DateTime.UtcNow; - Tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + Tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } } } -} \ No newline at end of file +}