diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs index ea3ba6e631..96f510ea45 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/ConnectionHandler.cs @@ -33,15 +33,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal var connectionId = CorrelationIdGenerator.GetNextId(); var frameConnectionId = Interlocked.Increment(ref _lastFrameConnectionId); - var frameContext = new FrameContext - { - ConnectionId = connectionId, - ConnectionInformation = connectionInfo, - ServiceContext = _serviceContext - }; - - var frame = new Frame(_application, frameContext); - var connection = new FrameConnection(new FrameConnectionContext { ConnectionId = connectionId, @@ -49,7 +40,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal ServiceContext = _serviceContext, ConnectionInformation = connectionInfo, ConnectionAdapters = _listenOptions.ConnectionAdapters, - Frame = frame, Input = inputPipe, Output = outputPipe, }); @@ -57,7 +47,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal // Since data cannot be added to the inputPipe by the transport until OnConnection returns, // Frame.ProcessRequestsAsync is guaranteed to unblock the transport thread before calling // application code. - connection.StartRequestProcessing(); + connection.StartRequestProcessing(_application); return connection; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs index b9d7bcfc55..9b4da51ec1 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnection.cs @@ -8,6 +8,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; @@ -20,9 +21,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public class FrameConnection : IConnectionContext, ITimeoutControl { private readonly FrameConnectionContext _context; - private readonly Frame _frame; private List _adaptedConnections; private readonly TaskCompletionSource _socketClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + private Frame _frame; private long _lastTimestamp; private long _timeoutTimestamp = long.MaxValue; @@ -33,7 +34,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public FrameConnection(FrameConnectionContext context) { _context = context; - _frame = context.Frame; } public string ConnectionId => _context.ConnectionId; @@ -61,12 +61,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal private IKestrelTrace Log => _context.ServiceContext.Log; - public void StartRequestProcessing() + public void StartRequestProcessing(IHttpApplication application) { - _lifetimeTask = ProcessRequestsAsync(); + _lifetimeTask = ProcessRequestsAsync(application); } - private async Task ProcessRequestsAsync() + private async Task ProcessRequestsAsync(IHttpApplication application) { try { @@ -90,11 +90,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal output = adaptedPipeline.Output; } - // Set these before the first await, this is to make sure that we don't yield control - // to the transport until we've added the connection to the connection manager - _frame.TimeoutControl = this; - _frame.Input = input; - _frame.Output = new OutputProducer(output, ConnectionId, Log); + // _frame must be initialized before adding the connection to the connection manager + _frame = new Frame(application, new FrameContext + { + ConnectionId = _context.ConnectionId, + ConnectionInformation = _context.ConnectionInformation, + ServiceContext = _context.ServiceContext, + TimeoutControl = this, + Input = input, + Output = output + }); + + // Do this before the first await so we don't yield control to the transport until we've + // added the connection to the connection manager _context.ServiceContext.ConnectionManager.AddConnection(_context.FrameConnectionId, this); _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; @@ -125,6 +133,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void OnConnectionClosed(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -133,6 +143,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public Task StopAsync() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + _frame.Stop(); return _lifetimeTask; @@ -140,12 +152,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Abort(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); } public Task AbortAsync(Exception ex) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + // Abort the connection (if not already aborted) _frame.Abort(ex); @@ -154,11 +170,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Timeout() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + _frame.SetBadRequestState(RequestRejectionReason.RequestTimeout); } private async Task ApplyConnectionAdaptersAsync() { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + var features = new FeatureCollection(); var connectionAdapters = _context.ConnectionAdapters; var stream = new RawStream(_context.Input.Reader, _context.Output.Writer); @@ -202,6 +222,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public void Tick(DateTimeOffset now) { + Debug.Assert(_frame != null, $"nameof({_frame}) is null"); + var timestamp = now.Ticks; // TODO: Use PlatformApis.VolatileRead equivalent again diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs index 24c30becbe..98faa9b237 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/FrameConnectionContext.cs @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal public ServiceContext ServiceContext { get; set; } public List ConnectionAdapters { get; set; } public IConnectionInformation ConnectionInformation { get; set; } - public Frame Frame { get; set; } public IPipe Input { get; set; } public IPipe Output { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs index 52ea21fb96..96abde3566 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/Frame.cs @@ -96,15 +96,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http FrameControl = this; _keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks; _requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks; + + Output = new OutputProducer(frameContext.Output, frameContext.ConnectionId, frameContext.ServiceContext.Log); } public ServiceContext ServiceContext => _frameContext.ServiceContext; public IConnectionInformation ConnectionInformation => _frameContext.ConnectionInformation; - public IPipeReader Input { get; set; } - public OutputProducer Output { get; set; } public IFeatureCollection ConnectionFeatures { get; set; } - public ITimeoutControl TimeoutControl { get; set; } + public IPipeReader Input => _frameContext.Input; + public OutputProducer Output { get; } + public ITimeoutControl TimeoutControl => _frameContext.TimeoutControl; protected IKestrelTrace Log => ServiceContext.Log; private DateHeaderValueManager DateHeaderValueManager => ServiceContext.DateHeaderValueManager; diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs index 28069ce4ae..12d6c22e95 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Core/Internal/Http/FrameContext.cs @@ -1,6 +1,8 @@ // 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 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; +using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http @@ -10,5 +12,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http public string ConnectionId { get; set; } public ServiceContext ServiceContext { get; set; } public IConnectionInformation ConnectionInformation { get; set; } + public ITimeoutControl TimeoutControl { get; set; } + public IPipeReader Input { get; set; } + public IPipe Output { get; set; } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs index ff60650c98..62c0f8a1de 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameResponseHeadersTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Primitives; @@ -22,7 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var frameContext = new FrameContext { ServiceContext = new TestServiceContext(), - ConnectionInformation = Mock.Of() + ConnectionInformation = Mock.Of(), + TimeoutControl = null }; var frame = new Frame(application: null, frameContext: frameContext); @@ -61,14 +63,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("Ser\u0080ver", "Data")] [InlineData("Server", "Da\u0080ta")] [InlineData("Unknown\u0080-Header", "Data")] - [InlineData("Ser™ver", "Data")] - [InlineData("Server", "Da™ta")] - [InlineData("Unknown™-Header", "Data")] - [InlineData("Ser™ver", "Data")] - [InlineData("šerver", "Data")] - [InlineData("Server", "Dašta")] - [InlineData("Unknownš-Header", "Data")] - [InlineData("Seršver", "Data")] + [InlineData("Ser™ver", "Data")] + [InlineData("Server", "Da™ta")] + [InlineData("Unknown™-Header", "Data")] + [InlineData("Ser™ver", "Data")] + [InlineData("šerver", "Data")] + [InlineData("Server", "Dašta")] + [InlineData("Unknownš-Header", "Data")] + [InlineData("Seršver", "Data")] public void AddingControlOrNonAsciiCharactersToHeadersThrows(string key, string value) { var responseHeaders = new FrameResponseHeaders(); @@ -259,4 +261,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests "42.000", }; } -} \ No newline at end of file +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs index 51ae37a73a..331ac40675 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/FrameTests.cs @@ -36,11 +36,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests private readonly PipeFactory _pipelineFactory; private ReadCursor _consumed; private ReadCursor _examined; + private Mock _timeoutControl; private class TestFrame : Frame { public TestFrame(IHttpApplication application, FrameContext context) - : base(application, context) + : base(application, context) { } @@ -57,21 +58,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var output = _pipelineFactory.Create(); _serviceContext = new TestServiceContext(); - + _timeoutControl = new Mock(); _frameContext = new FrameContext { ServiceContext = _serviceContext, - ConnectionInformation = Mock.Of() - }; - - _frame = new TestFrame(application: null, context: _frameContext) - { + ConnectionInformation = Mock.Of(), + TimeoutControl = _timeoutControl.Object, Input = _input.Reader, - TimeoutControl = Mock.Of() + Output = output }; - _frame.Output = new OutputProducer(output, "", Mock.Of()); - + _frame = new TestFrame(application: null, context: _frameContext); _frame.Reset(); } @@ -343,16 +340,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public async Task ParseRequestStartsRequestHeadersTimeoutOnFirstByteAvailable() { - var connectionControl = new Mock(); - _frame.TimeoutControl = connectionControl.Object; - await _input.Writer.WriteAsync(Encoding.ASCII.GetBytes("G")); _frame.ParseRequest((await _input.Reader.ReadAsync()).Buffer, out _consumed, out _examined); _input.Reader.Advance(_consumed, _examined); var expectedRequestHeadersTimeout = _serviceContext.ServerOptions.Limits.RequestHeadersTimeout.Ticks; - connectionControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); + _timeoutControl.Verify(cc => cc.ResetTimeout(expectedRequestHeadersTimeout, TimeoutAction.SendTimeoutResponse)); } [Fact] @@ -466,13 +460,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [Fact] public void ProcessRequestsAsyncEnablesKeepAliveTimeout() { - var connectionControl = new Mock(); - _frame.TimeoutControl = connectionControl.Object; - var requestProcessingTask = _frame.ProcessRequestsAsync(); var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks; - connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); + _timeoutControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection)); _frame.Stop(); _input.Writer.Complete(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs index 1ec0f7656c..3bdc4fef58 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/OutputProducerTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Testing; using Moq; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs index 56b959a738..25a38d495d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests/TestInput.cs @@ -7,10 +7,12 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Internal; +using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests { @@ -21,15 +23,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public TestInput() { - var innerContext = new FrameContext { ServiceContext = new TestServiceContext() }; - - FrameContext = new Frame(null, innerContext); - FrameContext.FrameControl = this; - _memoryPool = new MemoryPool(); _pipelineFactory = new PipeFactory(); + Pipe = _pipelineFactory.Create(); - FrameContext.Input = Pipe.Reader; + + FrameContext = new Frame(null, new FrameContext + { + ServiceContext = new TestServiceContext(), + Input = Pipe.Reader + }); + FrameContext.FrameControl = this; } public IPipe Pipe { get; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index 7128adae7d..71964abb79 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -28,7 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl() }; _frame = new Frame(application: null, frameContext: frameContext); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 74bbdc19c5..b1ba1658fb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -98,18 +99,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance Log = new MockTrace(), HttpParserFactory = f => new HttpParser() }; - var frameContext = new FrameContext + + var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() - }; - - var frame = new TestFrame(application: null, context: frameContext) - { + ConnectionInformation = new MockConnectionInformation(), Input = input.Reader, - }; - - frame.Output = new OutputProducer(output, "", null); + Output = output + }); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index 1cff65290f..c6d5e5263c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -30,11 +30,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance var frameContext = new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl() }; Frame = new Frame(application: null, frameContext: frameContext); - Frame.TimeoutControl = new MockTimeoutControl(); PipelineFactory = new PipeFactory(); Pipe = PipelineFactory.Create(); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index b494e30867..7a65a7d7a6 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -32,10 +32,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance } [Params( - BenchmarkTypes.ContentLengthNumeric, - BenchmarkTypes.ContentLengthString, - BenchmarkTypes.Plaintext, - BenchmarkTypes.Common, + BenchmarkTypes.ContentLengthNumeric, + BenchmarkTypes.ContentLengthString, + BenchmarkTypes.Plaintext, + BenchmarkTypes.Common, BenchmarkTypes.Unknown )] public BenchmarkTypes Type { get; set; } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 483705f3a2..659b903a8e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines; +using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance @@ -121,17 +122,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance HttpParserFactory = f => new HttpParser() }; - var frameContext = new FrameContext + var frame = new TestFrame(application: null, context: new FrameContext { ServiceContext = serviceContext, - ConnectionInformation = new MockConnectionInformation() - }; - - var frame = new TestFrame(application: null, context: frameContext) - { + ConnectionInformation = new MockConnectionInformation(), + TimeoutControl = new MockTimeoutControl(), Input = input.Reader, - }; - frame.Output = new OutputProducer(output, "", null); + Output = output + }); frame.Reset(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs index 16f3361be8..e24e667b7d 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests/LibuvOutputConsumerTests.cs @@ -693,12 +693,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests }; var transportContext = new TestLibuvTransportContext { Log = new LibuvTrace(logger) }; - var frame = new Frame(null, new FrameContext { ServiceContext = serviceContext }); - var socket = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log); - var outputProducer = new OutputProducer(pipe, "0", serviceContext.Log); var consumer = new LibuvOutputConsumer(pipe.Reader, _libuvThread, socket, "0", transportContext.Log); - frame.Output = outputProducer; + + var frame = new Frame(null, new FrameContext + { + ServiceContext = serviceContext, + TimeoutControl = Mock.Of(), + Output = pipe + }); if (cts != null) { @@ -707,7 +710,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests var ignore = WriteOutputAsync(consumer, pipe.Reader, frame); - return outputProducer; + return frame.Output; } private async Task WriteOutputAsync(LibuvOutputConsumer consumer, IPipeReader outputReader, Frame frame) @@ -729,4 +732,4 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests } } } -} \ No newline at end of file +} diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index 65eb198c8b..74b8bac07c 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -4,13 +4,14 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Testing { public class TestFrame : Frame { public TestFrame(IHttpApplication application, FrameContext context) - : base(application, context) + : base(application, context) { } @@ -31,4 +32,4 @@ namespace Microsoft.AspNetCore.Testing return ProduceEnd(); } } -} \ No newline at end of file +}