Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Refactored some functional tests. #1561

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -570,21 +570,9 @@ public PortSupportedConditionAttribute(int port)
_portSupported = new Lazy<bool>(CanBindToPort);
}

public bool IsMet
{
get
{
return _portSupported.Value;
}
}
public bool IsMet => _portSupported.Value;

public string SkipReason
{
get
{
return $"Cannot bind to port {_port} on the host.";
}
}
public string SkipReason => $"Cannot bind to port {_port} on the host.";

private bool CanBindToPort()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Testing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await connection.SendAll("GET / HTTP/1.1",

var stop = Assert.Single(events, e => e.EventName == "ConnectionStop");
Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, stop.PayloadNames));
Assert.Same(KestrelEventSource.Log, stop.EventSource);
Assert.Same(KestrelEventSource.Log, stop?.EventSource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ? is unnecessary since Assert.Single will fail if it can't find the stop event.

}

private string GetProperty(EventWrittenEventArgs data, string propName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnecti
httpContext.Abort();
try
{
await httpContext.Response.WriteAsync($"hello, world");
await httpContext.Response.WriteAsync("hello, world");
tcs.SetResult(null);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class MaxRequestBufferSizeTests
{
private const int _dataLength = 20 * 1024 * 1024;

private static readonly string[] _requestLines = new[]
{
private static readonly string[] _requestLines = {
"POST / HTTP/1.0\r\n",
$"Content-Length: {_dataLength}\r\n",
"\r\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Xunit;
using Microsoft.Extensions.Primitives;
using System.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task DoesNotHangOnConnectionCloseRequest()
{
var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app =>
{
app.Run(async context =>
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task StreamsAreNotPersistedAcrossRequests()

var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app =>
{
app.Run(async context =>
Expand Down Expand Up @@ -204,7 +204,7 @@ public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader()
var dataRead = false;
var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app =>
{
app.Run(async context =>
Expand Down Expand Up @@ -251,29 +251,23 @@ public async Task ConnectionResetPriorToRequestIsLoggedAsDebug()
.Returns(true);
mockLogger
.Setup(logger => logger.Log(LogLevel.Debug, _connectionStartedEventId, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()))
.Callback(() =>
{
connectionStarted.Release();
});
.Callback(() => connectionStarted.Release());
mockLogger
.Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()))
.Callback(() =>
{
connectionReset.Release();
});
.Callback(() => connectionReset.Release());

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory
.Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"))
.Returns(mockLogger.Object);
mockLoggerFactory
.Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" })))
.Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel")))
.Returns(Mock.Of<ILogger>());

var builder = new WebHostBuilder()
.UseLoggerFactory(mockLoggerFactory.Object)
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app => app.Run(context => TaskCache.CompletedTask));

using (var host = builder.Build())
Expand Down Expand Up @@ -311,30 +305,24 @@ public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug()
.Returns(true);
mockLogger
.Setup(logger => logger.Log(LogLevel.Debug, _connectionKeepAliveEventId, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()))
.Callback(() =>
{
requestDone.Release();
});
.Callback(() => requestDone.Release());
mockLogger
.Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()))
.Callback(() =>
{
connectionReset.Release();
});
.Callback(() => connectionReset.Release());

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory
.Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"))
.Returns(mockLogger.Object);
mockLoggerFactory
.Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" })))
.Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel")))
.Returns(Mock.Of<ILogger>());


var builder = new WebHostBuilder()
.UseLoggerFactory(mockLoggerFactory.Object)
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app => app.Run(context => TaskCache.CompletedTask));

using (var host = builder.Build())
Expand Down Expand Up @@ -372,25 +360,22 @@ public async Task ConnectionResetMidRequestIsLoggedAsDebug()
.Returns(true);
mockLogger
.Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny<object>(), null, It.IsAny<Func<object, Exception, string>>()))
.Callback(() =>
{
connectionReset.Release();
});
.Callback(() => connectionReset.Release());

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory
.Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel"))
.Returns(mockLogger.Object);
mockLoggerFactory
.Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" })))
.Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel")))
.Returns(Mock.Of<ILogger>());

var requestStarted = new SemaphoreSlim(0);

var builder = new WebHostBuilder()
.UseLoggerFactory(mockLoggerFactory.Object)
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app => app.Run(async context =>
{
requestStarted.Release();
Expand Down Expand Up @@ -431,7 +416,7 @@ public async Task ThrowsOnReadAfterConnectionError()

var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app => app.Run(async context =>
{
requestStarted.Release();
Expand Down Expand Up @@ -475,14 +460,14 @@ public async Task RequestAbortedTokenFiredOnClientFIN()
var requestAborted = new SemaphoreSlim(0);
var builder = new WebHostBuilder()
.UseKestrel()
.UseUrls($"http://127.0.0.1:0")
.UseUrls("http://127.0.0.1:0")
.Configure(app => app.Run(async context =>
{
appStarted.Release();

var token = context.RequestAborted;
token.Register(() => requestAborted.Release(2));
await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10));
await requestAborted.WaitAsync(token).TimeoutAfter(TimeSpan.FromSeconds(10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't tie the semaphore to the cancellation token.

}));

using (var host = builder.Build())
Expand Down
Loading