From ff99c4c865097f7b3dbbe64d30d489298a32df4c Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 23 Mar 2017 01:30:06 +0000 Subject: [PATCH] Fix benchmarks (broken) (#1515) * Fix benchmarks * Remove Moq from benchmarks --- .../FrameParsingOverheadBenchmark.cs | 1 + .../FrameWritingBenchmark.cs | 6 +-- ...pNetCore.Server.Kestrel.Performance.csproj | 1 - .../Mocks/MockConnectionControl.cs | 17 +++++++++ .../Mocks/MockTrace.cs | 37 +++++++++++++++++++ .../RequestParsingBenchmark.cs | 1 + .../ResponseHeaderCollectionBenchmark.cs | 1 + .../ResponseHeadersWritingBenchmark.cs | 8 ++-- test/shared/TestFrame.cs | 12 ++++++ 9 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs create mode 100644 test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index a772eee781..2b5065707a 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance; + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); _frame = new Frame(application: null, context: connectionContext); } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index d632e337cd..ffb4e95b62 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -9,9 +9,7 @@ using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -95,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = Mock.Of() + Log = new MockTrace() }; var listenerContext = new ListenerContext(serviceContext) { @@ -105,7 +103,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Input = socketInput, Output = new MockSocketOutput(), - ConnectionControl = Mock.Of() + ConnectionControl = new MockConnectionControl() }; connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj index 88b306a3d0..8718f3f9ae 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Microsoft.AspNetCore.Server.Kestrel.Performance.csproj @@ -24,7 +24,6 @@ - diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs new file mode 100644 index 0000000000..14e53e3f53 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs @@ -0,0 +1,17 @@ +// 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.Internal.Http; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockConnectionControl : IConnectionControl + { + public void CancelTimeout() { } + public void End(ProduceEndType endType) { } + public void Pause() { } + public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction) { } + public void Resume() { } + public void SetTimeout(long milliseconds, TimeoutAction timeoutAction) { } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs new file mode 100644 index 0000000000..f7737a63f9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockTrace.cs @@ -0,0 +1,37 @@ +// 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; +using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.Kestrel.Performance +{ + public class MockTrace : IKestrelTrace + { + public void ApplicationError(string connectionId, Exception ex) { } + public IDisposable BeginScope(TState state) => null; + public void ConnectionBadRequest(string connectionId, BadHttpRequestException ex) { } + public void ConnectionDisconnect(string connectionId) { } + public void ConnectionDisconnectedWrite(string connectionId, int count, Exception ex) { } + public void ConnectionError(string connectionId, Exception ex) { } + public void ConnectionHeadResponseBodyWrite(string connectionId, long count) { } + public void ConnectionKeepAlive(string connectionId) { } + public void ConnectionPause(string connectionId) { } + public void ConnectionRead(string connectionId, int count) { } + public void ConnectionReadFin(string connectionId) { } + public void ConnectionReset(string connectionId) { } + public void ConnectionResume(string connectionId) { } + public void ConnectionStart(string connectionId) { } + public void ConnectionStop(string connectionId) { } + public void ConnectionWrite(string connectionId, int count) { } + public void ConnectionWriteCallback(string connectionId, int status) { } + public void ConnectionWriteFin(string connectionId) { } + public void ConnectionWroteFin(string connectionId, int status) { } + public bool IsEnabled(LogLevel logLevel) => false; + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) { } + public void NotAllConnectionsAborted() { } + public void NotAllConnectionsClosedGracefully() { } + public void RequestProcessingError(string connectionId, Exception ex) { } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index dc07d53270..8e29354eeb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); Frame = new Frame(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs index 48b79138b5..f8668024af 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs @@ -169,6 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { var connectionContext = new MockConnection(); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); var frame = new Frame(application: null, context: connectionContext); frame.Reset(); frame.InitializeHeaders(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs index 0fb6aab65d..642ad4e57c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs @@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { @@ -39,6 +38,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { _frame.Reset(); _frame.StatusCode = 200; + _frame.HttpVersionEnum = HttpVersion.Http11; + _frame.KeepAlive = true; Task writeTask = Task.CompletedTask; switch (Type) @@ -119,7 +120,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { DateHeaderValueManager = new DateHeaderValueManager(), ServerOptions = new KestrelServerOptions(), - Log = Mock.Of() + Log = new MockTrace() }; var listenerContext = new ListenerContext(serviceContext) @@ -131,10 +132,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Input = input, Output = socketOutput, - ConnectionControl = Mock.Of() + ConnectionControl = new MockConnectionControl() }; connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(log: null); + connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions(); var frame = new TestFrame(application: null, context: connectionContext); frame.Reset(); diff --git a/test/shared/TestFrame.cs b/test/shared/TestFrame.cs index 4ccba9bd4a..5eda865139 100644 --- a/test/shared/TestFrame.cs +++ b/test/shared/TestFrame.cs @@ -14,6 +14,18 @@ namespace Microsoft.AspNetCore.Testing { } + public HttpVersion HttpVersionEnum + { + get => _httpVersion; + set => _httpVersion = value; + } + + public bool KeepAlive + { + get => _keepAlive; + set => _keepAlive = value; + } + public Task ProduceEndAsync() { return ProduceEnd();