Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#1089)

Instead of Task.FromResult(0)
This commit is contained in:
Pavel Krymets 2016-09-09 15:57:33 -07:00 committed by GitHub
parent 5b2065230d
commit c777a9efea
23 changed files with 70 additions and 64 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
{ {
@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{ {
return Task.FromResult(0); return TaskCache<int>.DefaultCompletedTask;
} }
public override void Write(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count)

View File

@ -3,9 +3,7 @@
using System.Reflection; using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: AssemblyMetadata("Serviceable", "True")] [assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")] [assembly: NeutralResourcesLanguage("en-us")]
[assembly: AssemblyCompany("Microsoft Corporation.")] [assembly: AssemblyCompany("Microsoft Corporation.")]

View File

@ -19,7 +19,11 @@
] ]
}, },
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*" "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
"Microsoft.Extensions.TaskCache.Sources": {
"version": "1.1.0-*",
"type": "build"
}
}, },
"frameworks": { "frameworks": {
"net451": {}, "net451": {},

View File

@ -6,18 +6,16 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal
{ {
public class LibuvStream : Stream public class LibuvStream : Stream
{ {
private readonly static Task<int> _initialCachedTask = Task.FromResult(0);
private readonly SocketInput _input; private readonly SocketInput _input;
private readonly ISocketOutput _output; private readonly ISocketOutput _output;
private Task<int> _cachedTask = _initialCachedTask; private Task<int> _cachedTask = TaskCache<int>.DefaultCompletedTask;
public LibuvStream(SocketInput input, ISocketOutput output) public LibuvStream(SocketInput input, ISocketOutput output)
{ {
@ -125,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter.Internal
public override Task FlushAsync(CancellationToken cancellationToken) public override Task FlushAsync(CancellationToken cancellationToken)
{ {
// No-op since writes are immediate. // No-op since writes are immediate.
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
private ValueTask<int> ReadAsync(ArraySegment<byte> buffer) private ValueTask<int> ReadAsync(ArraySegment<byte> buffer)

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Filter namespace Microsoft.AspNetCore.Server.Kestrel.Filter
{ {
@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Filter
{ {
public Task OnConnectionAsync(ConnectionFilterContext context) public Task OnConnectionAsync(ConnectionFilterContext context)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
} }
} }

View File

@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
@ -338,7 +339,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
_requestProcessingStopping = true; _requestProcessingStopping = true;
} }
return _requestProcessingTask ?? TaskUtilities.CompletedTask; return _requestProcessingTask ?? TaskCache.CompletedTask;
} }
/// <summary> /// <summary>
@ -500,7 +501,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
if (data.Count == 0) if (data.Count == 0)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
return WriteChunkedAsync(data, cancellationToken); return WriteChunkedAsync(data, cancellationToken);
} }
@ -569,7 +570,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
if (HasResponseStarted) if (HasResponseStarted)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
if (_onStarting != null) if (_onStarting != null)
@ -583,7 +584,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
ProduceStart(appCompleted: false); ProduceStart(appCompleted: false);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
private async Task ProduceStartAndFireOnStartingAwaited() private async Task ProduceStartAndFireOnStartingAwaited()
@ -624,7 +625,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
return ProduceEnd(); return ProduceEnd();
} }
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
protected Task ProduceEnd() protected Task ProduceEnd()
@ -635,7 +636,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
// We can no longer change the response, so we simply close the connection. // We can no longer change the response, so we simply close the connection.
_requestProcessingStopping = true; _requestProcessingStopping = true;
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
if (_requestRejected) if (_requestRejected)
@ -697,7 +698,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); ConnectionControl.End(ProduceEndType.ConnectionKeepAlive);
} }
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
private async Task WriteAutoChunkSuffixAwaited() private async Task WriteAutoChunkSuffixAwaited()

View File

@ -6,6 +6,7 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
public override Task FlushAsync(CancellationToken cancellationToken) public override Task FlushAsync(CancellationToken cancellationToken)
{ {
// No-op. // No-op.
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
public override long Seek(long offset, SeekOrigin origin) public override long Seek(long offset, SeekOrigin origin)

View File

@ -5,7 +5,7 @@ using System;
using System.Numerics; using System.Numerics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
else if (result.Result == 0) else if (result.Result == 0)
{ {
// Completed Task, end of stream // Completed Task, end of stream
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
} while (true); } while (true);

View File

@ -8,6 +8,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
@ -98,7 +99,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
_log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError); _log.ConnectionDisconnectedWrite(_connectionId, buffer.Count, _lastWriteError);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
if (buffer.Count > 0) if (buffer.Count > 0)
@ -106,7 +107,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
var tail = ProducingStart(); var tail = ProducingStart();
if (tail.IsDefault) if (tail.IsDefault)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
if (chunk) if (chunk)
@ -201,7 +202,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
// Return TaskCompletionSource's Task if set, otherwise completed Task // Return TaskCompletionSource's Task if set, otherwise completed Task
return tcs?.Task ?? TaskUtilities.CompletedTask; return tcs?.Task ?? TaskCache.CompletedTask;
} }
public void End(ProduceEndType endType) public void End(ProduceEndType endType)
@ -523,7 +524,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (_cancelled) else if (_cancelled)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
return WriteAsync(buffer, cancellationToken, chunk); return WriteAsync(buffer, cancellationToken, chunk);

View File

@ -9,13 +9,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{ {
public static class TaskUtilities public static class TaskUtilities
{ {
#if NETSTANDARD1_3
public static Task CompletedTask = Task.CompletedTask;
#else
public static Task CompletedTask = Task.FromResult<object>(null);
#endif
public static Task<int> ZeroTask = Task.FromResult(0);
public static Task GetCancelledTask(CancellationToken cancellationToken) public static Task GetCancelledTask(CancellationToken cancellationToken)
{ {
#if NETSTANDARD1_3 #if NETSTANDARD1_3

View File

@ -18,7 +18,11 @@
"System.Threading.Tasks.Extensions": "4.0.0-*", "System.Threading.Tasks.Extensions": "4.0.0-*",
"Libuv": "1.9.0-*", "Libuv": "1.9.0-*",
"Microsoft.AspNetCore.Hosting": "1.1.0-*", "Microsoft.AspNetCore.Hosting": "1.1.0-*",
"Microsoft.Extensions.Logging.Abstractions": "1.1.0-*" "Microsoft.Extensions.Logging.Abstractions": "1.1.0-*",
"Microsoft.Extensions.TaskCache.Sources": {
"version": "1.1.0-*",
"type": "build"
}
}, },
"frameworks": { "frameworks": {
"net451": { "net451": {

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Xunit; using Xunit;
@ -159,7 +159,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
{ {
await context.Response.WriteAsync("hello, world"); await context.Response.WriteAsync("hello, world");
await context.Response.Body.FlushAsync(); await context.Response.Body.FlushAsync();
ex = Assert.Throws<InvalidOperationException>(() => context.Response.OnStarting(_ => TaskUtilities.CompletedTask, null)); ex = Assert.Throws<InvalidOperationException>(() => context.Response.OnStarting(_ => TaskCache.CompletedTask, null));
}); });
}); });

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
[InlineData("post= / HTTP/1.0\r\n")] [InlineData("post= / HTTP/1.0\r\n")]
public async Task TestInvalidRequestLines(string request) public async Task TestInvalidRequestLines(string request)
{ {
using (var server = new TestServer(context => TaskUtilities.CompletedTask)) using (var server = new TestServer(context => TaskCache.CompletedTask))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
[InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")] [InlineData("Header-1: value1\r\nHeader-2\t: value2\r\n\r\n")]
public async Task TestInvalidHeaders(string rawHeaders) public async Task TestInvalidHeaders(string rawHeaders)
{ {
using (var server = new TestServer(context => TaskUtilities.CompletedTask)) using (var server = new TestServer(context => TaskCache.CompletedTask))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {

View File

@ -3,10 +3,10 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
var context = new ListenerContext(new TestServiceContext()) var context = new ListenerContext(new TestServiceContext())
{ {
FrameFactory = connectionContext => new Frame<HttpContext>( FrameFactory = connectionContext => new Frame<HttpContext>(
new DummyApplication(httpContext => TaskUtilities.CompletedTask), connectionContext), new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext),
ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"),
Thread = engine.Threads[0] Thread = engine.Threads[0]
}; };

View File

@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
ServerOptions = { AddServerHeader = true } ServerOptions = { AddServerHeader = true }
}; };
using (var server = new TestServer(ctx => TaskUtilities.CompletedTask, testContext)) using (var server = new TestServer(ctx => TaskCache.CompletedTask, testContext))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {

View File

@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -1084,7 +1085,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var server = new TestServer(httpContext => using (var server = new TestServer(httpContext =>
{ {
httpContext.Abort(); httpContext.Abort();
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, testContext)) }, testContext))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
@ -1121,7 +1122,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
Assert.Same(originalRequestHeaders, requestFeature.Headers); Assert.Same(originalRequestHeaders, requestFeature.Headers);
} }
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, testContext)) }, testContext))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
@ -1168,7 +1169,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
Assert.Same(originalResponseHeaders, responseFeature.Headers); Assert.Same(originalResponseHeaders, responseFeature.Headers);
} }
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, testContext)) }, testContext))
{ {
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
@ -1234,12 +1235,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
context.Response.OnStarting(_ => context.Response.OnStarting(_ =>
{ {
callOrder.Push(1); callOrder.Push(1);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, null); }, null);
context.Response.OnStarting(_ => context.Response.OnStarting(_ =>
{ {
callOrder.Push(2); callOrder.Push(2);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, null); }, null);
context.Response.ContentLength = response.Length; context.Response.ContentLength = response.Length;
@ -1278,12 +1279,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
context.Response.OnCompleted(_ => context.Response.OnCompleted(_ =>
{ {
callOrder.Push(1); callOrder.Push(1);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, null); }, null);
context.Response.OnCompleted(_ => context.Response.OnCompleted(_ =>
{ {
callOrder.Push(2); callOrder.Push(2);
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
}, null); }, null);
context.Response.ContentLength = response.Length; context.Response.ContentLength = response.Length;

View File

@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
@ -629,7 +630,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
// Act/Assert // Act/Assert
Assert.True(frame.HasResponseStarted); Assert.True(frame.HasResponseStarted);
Assert.Throws<InvalidOperationException>(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskUtilities.CompletedTask, null)); Assert.Throws<InvalidOperationException>(() => ((IHttpResponseFeature)frame).OnStarting(_ => TaskCache.CompletedTask, null));
} }
[Fact] [Fact]

View File

@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Server.Kestrel.Https;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Moq; using Moq;
using Xunit; using Xunit;
@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
new NoOpConnectionFilter()) new NoOpConnectionFilter())
); );
using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress))
{ {
using (var client = new TcpClient()) using (var client = new TcpClient())
{ {
@ -231,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
new NoOpConnectionFilter()) new NoOpConnectionFilter())
); );
using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress))
{ {
using (var client = new TcpClient()) using (var client = new TcpClient())
{ {
@ -258,7 +259,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
new NoOpConnectionFilter()) new NoOpConnectionFilter())
); );
using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress))
{ {
using (var client = new TcpClient()) using (var client = new TcpClient())
{ {
@ -283,7 +284,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
new NoOpConnectionFilter()) new NoOpConnectionFilter())
); );
using (var server = new TestServer(context => TaskUtilities.CompletedTask, serviceContext, _serverAddress)) using (var server = new TestServer(context => TaskCache.CompletedTask, serviceContext, _serverAddress))
{ {
using (var client = new TcpClient()) using (var client = new TcpClient())
{ {

View File

@ -5,8 +5,8 @@ using System;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Moq; using Moq;
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
private static void StartDummyApplication(IServer server) private static void StartDummyApplication(IServer server)
{ {
server.Start(new DummyApplication(context => TaskUtilities.CompletedTask)); server.Start(new DummyApplication(context => TaskCache.CompletedTask));
} }
private class TestLoggerFactory : ILoggerFactory private class TestLoggerFactory : ILoggerFactory

View File

@ -5,7 +5,7 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{ {
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
public Task FlushAsync(CancellationToken cancellationToken) public Task FlushAsync(CancellationToken cancellationToken)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
public void ProduceContinue() public void ProduceContinue()
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
public Task WriteAsync(ArraySegment<byte> data, CancellationToken cancellationToken) public Task WriteAsync(ArraySegment<byte> data, CancellationToken cancellationToken)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
} }
} }

View File

@ -6,6 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{ {
@ -26,7 +27,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
public Task WriteAsync(ArraySegment<byte> buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken)) public Task WriteAsync(ArraySegment<byte> buffer, bool chunk = false, CancellationToken cancellationToken = default(CancellationToken))
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
} }
} }

View File

@ -4,8 +4,8 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Filter; using Microsoft.AspNetCore.Server.Kestrel.Filter;
using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Filter.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public Task OnConnectionAsync(ConnectionFilterContext context) public Task OnConnectionAsync(ConnectionFilterContext context)
{ {
context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger());
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
} }
} }

View File

@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers; using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Server.KestrelTests namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
@ -84,7 +85,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
Task IFrameControl.WriteAsync(ArraySegment<byte> data, CancellationToken cancellationToken) Task IFrameControl.WriteAsync(ArraySegment<byte> data, CancellationToken cancellationToken)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
void IFrameControl.Flush() void IFrameControl.Flush()
@ -93,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
Task IFrameControl.FlushAsync(CancellationToken cancellationToken) Task IFrameControl.FlushAsync(CancellationToken cancellationToken)
{ {
return TaskUtilities.CompletedTask; return TaskCache.CompletedTask;
} }
public void Dispose() public void Dispose()