Server per test (#3253)

This commit is contained in:
BrennanConroy 2018-11-06 09:33:15 -08:00 committed by GitHub
parent b006a2c789
commit ffd4bcd850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 164 additions and 167 deletions

View File

@ -22,23 +22,24 @@ using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{ {
// Disable running server tests in parallel so server logs can accurately be captured per test public class HubConnectionTestsCollection : ICollectionFixture<InProcessTestServer<Startup>>
[CollectionDefinition(Name, DisableParallelization = true)]
public class HubConnectionTestsCollection : ICollectionFixture<ServerFixture<Startup>>
{ {
public const string Name = nameof(HubConnectionTestsCollection); public const string Name = nameof(HubConnectionTestsCollection);
} }
[Collection(HubConnectionTestsCollection.Name)] [Collection(HubConnectionTestsCollection.Name)]
public class HubConnectionTests : VerifiableServerLoggedTest public class HubConnectionTests : FunctionalTestBase
{ {
private const string DefaultHubDispatcherLoggerName = "SERVER Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher"; private const string DefaultHubDispatcherLoggerName = "Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher";
public HubConnectionTests(ServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(serverFixture, output) // Pass null for server fixture as tests should provide their own
// This is to prevent logs from previous tests affecting running tests
public HubConnectionTests(ITestOutputHelper output) : base(output)
{ {
} }
private HubConnection CreateHubConnection( private HubConnection CreateHubConnection(
string url,
string path = null, string path = null,
HttpTransportType? transportType = null, HttpTransportType? transportType = null,
IHubProtocol protocol = null, IHubProtocol protocol = null,
@ -49,18 +50,18 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
hubConnectionBuilder.WithLoggerFactory(loggerFactory); hubConnectionBuilder.WithLoggerFactory(loggerFactory);
var delegateConnectionFactory = new DelegateConnectionFactory( var delegateConnectionFactory = new DelegateConnectionFactory(
GetHttpConnectionFactory(loggerFactory, path, transportType ?? HttpTransportType.LongPolling | HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents), GetHttpConnectionFactory(url, loggerFactory, path, transportType ?? HttpTransportType.LongPolling | HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents),
connection => ((HttpConnection)connection).DisposeAsync()); connection => ((HttpConnection)connection).DisposeAsync());
hubConnectionBuilder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory); hubConnectionBuilder.Services.AddSingleton<IConnectionFactory>(delegateConnectionFactory);
return hubConnectionBuilder.Build(); return hubConnectionBuilder.Build();
} }
private Func<TransferFormat, Task<ConnectionContext>> GetHttpConnectionFactory(ILoggerFactory loggerFactory, string path, HttpTransportType transportType) private Func<TransferFormat, Task<ConnectionContext>> GetHttpConnectionFactory(string url, ILoggerFactory loggerFactory, string path, HttpTransportType transportType)
{ {
return async format => return async format =>
{ {
var connection = new HttpConnection(new Uri(ServerFixture.Url + path), transportType, loggerFactory); var connection = new HttpConnection(new Uri(url + path), transportType, loggerFactory);
await connection.StartAsync(format); await connection.StartAsync(format);
return connection; return connection;
}; };
@ -71,11 +72,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CheckFixedMessage(string protocolName, HttpTransportType transportType, string path) public async Task CheckFixedMessage(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(CheckFixedMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(CheckFixedMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + path, transportType); .WithUrl(fixture.Url + path, transportType);
connectionBuilder.Services.AddSingleton(protocol); connectionBuilder.Services.AddSingleton(protocol);
var connection = connectionBuilder.Build(); var connection = connectionBuilder.Build();
@ -105,10 +106,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportType transportType, string path) public async Task CanSendAndReceiveMessage(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(CanSendAndReceiveMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(CanSendAndReceiveMessage)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -134,10 +135,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStopAndStartConnection(string protocolName, HttpTransportType transportType, string path) public async Task CanStopAndStartConnection(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(CanStopAndStartConnection)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStopAndStartConnection)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -165,12 +166,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTransportType transportType, string path) public async Task CanStartConnectionFromClosedEvent(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(CanStartConnectionFromClosedEvent)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStartConnectionFromClosedEvent)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var logger = loggerFactory.CreateLogger<HubConnectionTests>(); var logger = loggerFactory.CreateLogger<HubConnectionTests>();
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var restartTcs = new TaskCompletionSource<object>(); var restartTcs = new TaskCompletionSource<object>();
connection.Closed += async e => connection.Closed += async e =>
{ {
@ -227,10 +228,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task MethodsAreCaseInsensitive(string protocolName, HttpTransportType transportType, string path) public async Task MethodsAreCaseInsensitive(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(MethodsAreCaseInsensitive)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(MethodsAreCaseInsensitive)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -256,11 +257,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanInvokeClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task CanInvokeClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(CanInvokeClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanInvokeClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
const string originalMessage = "SignalR"; const string originalMessage = "SignalR";
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -289,9 +290,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task InvokeNonExistantClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task InvokeNonExistantClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(InvokeNonExistantClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(InvokeNonExistantClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
var closeTcs = new TaskCompletionSource<object>(); var closeTcs = new TaskCompletionSource<object>();
connection.Closed += e => connection.Closed += e =>
{ {
@ -330,9 +331,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanStreamClientMethodFromServer(string protocolName, HttpTransportType transportType, string path) public async Task CanStreamClientMethodFromServer(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(CanStreamClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanStreamClientMethodFromServer)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -359,9 +360,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path) public async Task CanCloseStreamMethodEarly(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(CanCloseStreamMethodEarly)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(CanCloseStreamMethodEarly)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -399,9 +400,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path) public async Task StreamDoesNotStartIfTokenAlreadyCanceled(string protocolName, HttpTransportType transportType, string path)
{ {
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, LogLevel.Trace, $"{nameof(StreamDoesNotStartIfTokenAlreadyCanceled)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}"))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -434,9 +435,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var protocol = HubProtocols[protocolName]; var protocol = HubProtocols[protocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ExceptionFromStreamingSentToClient)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ExceptionFromStreamingSentToClient)}_{protocol.Name}_{transportType}_{path.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(path, transportType, protocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, path, transportType, protocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -468,9 +469,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -501,9 +502,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfHubMethodCannotBeResolvedAndArgumentsPassedIn)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -534,9 +535,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -567,9 +568,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -600,9 +601,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfStreamingHubMethodCannotBeResolved)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -634,10 +635,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentCountMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
loggerFactory.AddConsole(LogLevel.Trace); loggerFactory.AddConsole(LogLevel.Trace);
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -669,9 +670,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionOnStreamingHubMethodArgumentTypeMismatch)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -703,9 +704,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfNonStreamMethodInvokedWithStreamAsync)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -736,9 +737,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfStreamMethodInvokedWithInvoke)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -769,9 +770,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
} }
var hubProtocol = HubProtocols[hubProtocolName]; var hubProtocol = HubProtocols[hubProtocolName];
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ServerThrowsHubExceptionIfBuildingAsyncEnumeratorIsNotPossible)}_{hubProtocol.Name}_{transportType}_{hubPath.TrimStart('/')}", expectedErrorsFilter: ExpectedErrors))
{ {
var connection = CreateHubConnection(hubPath, transportType, hubProtocol, loggerFactory); var connection = CreateHubConnection(fixture.Url, hubPath, transportType, hubProtocol, loggerFactory);
try try
{ {
await connection.StartAsync().OrTimeout(); await connection.StartAsync().OrTimeout();
@ -795,18 +796,18 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthentication(HttpTransportType transportType) public async Task ClientCanUseJwtBearerTokenForAuthentication(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientCanUseJwtBearerTokenForAuthentication)}_{transportType}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanUseJwtBearerTokenForAuthentication)}_{transportType}"))
{ {
async Task<string> AccessTokenProvider() async Task<string> AccessTokenProvider()
{ {
var httpResponse = await new HttpClient().GetAsync(ServerFixture.Url + "/generateJwtToken"); var httpResponse = await new HttpClient().GetAsync(fixture.Url + "/generateJwtToken");
httpResponse.EnsureSuccessStatusCode(); httpResponse.EnsureSuccessStatusCode();
return await httpResponse.Content.ReadAsStringAsync(); return await httpResponse.Content.ReadAsStringAsync();
}; };
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/authorizedhub", transportType, options => .WithUrl(fixture.Url + "/authorizedhub", transportType, options =>
{ {
options.AccessTokenProvider = AccessTokenProvider; options.AccessTokenProvider = AccessTokenProvider;
}) })
@ -833,11 +834,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected(HttpTransportType transportType) public async Task ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected)}_{transportType}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanUseJwtBearerTokenForAuthenticationWhenRedirected)}_{transportType}"))
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/redirect", transportType) .WithUrl(fixture.Url + "/redirect", transportType)
.Build(); .Build();
try try
{ {
@ -861,11 +862,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientCanSendHeaders(HttpTransportType transportType) public async Task ClientCanSendHeaders(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientCanSendHeaders)}_{transportType}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(ClientCanSendHeaders)}_{transportType}"))
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/default", transportType, options => .WithUrl(fixture.Url + "/default", transportType, options =>
{ {
options.Headers["X-test"] = "42"; options.Headers["X-test"] = "42";
options.Headers["X-42"] = "test"; options.Headers["X-42"] = "test";
@ -893,15 +894,15 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketOptionsAreApplied() public async Task WebSocketOptionsAreApplied()
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(WebSocketOptionsAreApplied)}")) using (StartServer<Startup>(out var loggerFactory, out var fixture, $"{nameof(WebSocketOptionsAreApplied)}"))
{ {
// System.Net has a HttpTransportType type which means we need to fully-qualify this rather than 'use' the namespace // System.Net has a HttpTransportType type which means we need to fully-qualify this rather than 'use' the namespace
var cookieJar = new System.Net.CookieContainer(); var cookieJar = new System.Net.CookieContainer();
cookieJar.Add(new System.Net.Cookie("Foo", "Bar", "/", new Uri(ServerFixture.Url).Host)); cookieJar.Add(new System.Net.Cookie("Foo", "Bar", "/", new Uri(fixture.Url).Host));
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/default", HttpTransportType.WebSockets, options => .WithUrl(fixture.Url + "/default", HttpTransportType.WebSockets, options =>
{ {
options.WebSocketConfiguration = o => o.Cookies = cookieJar; options.WebSocketConfiguration = o => o.Cookies = cookieJar;
}) })
@ -927,11 +928,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task CheckHttpConnectionFeatures() public async Task CheckHttpConnectionFeatures()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var fixture))
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/default") .WithUrl(fixture.Url + "/default")
.Build(); .Build();
try try
{ {
@ -963,11 +964,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task UserIdProviderCanAccessHttpContext() public async Task UserIdProviderCanAccessHttpContext()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var fixture))
{ {
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/default", options => .WithUrl(fixture.Url + "/default", options =>
{ {
options.Headers.Add(HeaderUserIdProvider.HeaderName, "SuperAdmin"); options.Headers.Add(HeaderUserIdProvider.HeaderName, "SuperAdmin");
}) })
@ -994,12 +995,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task NegotiationSkipsServerSentEventsWhenUsingBinaryProtocol() public async Task NegotiationSkipsServerSentEventsWhenUsingBinaryProtocol()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var fixture))
{ {
var hubConnectionBuilder = new HubConnectionBuilder() var hubConnectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.AddMessagePackProtocol() .AddMessagePackProtocol()
.WithUrl(ServerFixture.Url + "/default-nowebsockets"); .WithUrl(fixture.Url + "/default-nowebsockets");
var hubConnection = hubConnectionBuilder.Build(); var hubConnection = hubConnectionBuilder.Build();
try try
@ -1024,12 +1025,12 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[Fact] [Fact]
public async Task StopCausesPollToReturnImmediately() public async Task StopCausesPollToReturnImmediately()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var fixture))
{ {
PollTrackingMessageHandler pollTracker = null; PollTrackingMessageHandler pollTracker = null;
var hubConnection = new HubConnectionBuilder() var hubConnection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/default", options => .WithUrl(fixture.Url + "/default", options =>
{ {
options.Transports = HttpTransportType.LongPolling; options.Transports = HttpTransportType.LongPolling;
options.HttpMessageHandlerFactory = handler => options.HttpMessageHandlerFactory = handler =>

View File

@ -23,17 +23,15 @@ using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{ {
// Disable running server tests in parallel so server logs can accurately be captured per test public class HubProtocolVersionTestsCollection : ICollectionFixture<InProcessTestServer<VersionStartup>>
[CollectionDefinition(Name, DisableParallelization = true)]
public class HubProtocolVersionTestsCollection : ICollectionFixture<ServerFixture<VersionStartup>>
{ {
public const string Name = nameof(HubProtocolVersionTestsCollection); public const string Name = nameof(HubProtocolVersionTestsCollection);
} }
[Collection(HubProtocolVersionTestsCollection.Name)] [Collection(HubProtocolVersionTestsCollection.Name)]
public class HubProtocolVersionTests : VerifiableServerLoggedTest public class HubProtocolVersionTests : FunctionalTestBase
{ {
public HubProtocolVersionTests(ServerFixture<VersionStartup> serverFixture, ITestOutputHelper output) : base(serverFixture, output) public HubProtocolVersionTests(ITestOutputHelper output) : base(output)
{ {
} }
@ -41,11 +39,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithOriginalProtocol(HttpTransportType transportType) public async Task ClientUsingOldCallWithOriginalProtocol(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientUsingOldCallWithOriginalProtocol)}_{transportType}")) using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingOldCallWithOriginalProtocol)}_{transportType}"))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/version", transportType); .WithUrl(server.Url + "/version", transportType);
var connection = connectionBuilder.Build(); var connection = connectionBuilder.Build();
@ -73,11 +71,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingOldCallWithNewProtocol(HttpTransportType transportType) public async Task ClientUsingOldCallWithNewProtocol(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientUsingOldCallWithNewProtocol)}_{transportType}")) using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingOldCallWithNewProtocol)}_{transportType}"))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/version", transportType); .WithUrl(server.Url + "/version", transportType);
connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(1000)); connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(1000));
var connection = connectionBuilder.Build(); var connection = connectionBuilder.Build();
@ -106,11 +104,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportType) public async Task ClientUsingNewCallWithNewProtocol(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, $"{nameof(ClientUsingNewCallWithNewProtocol)}_{transportType}")) using (StartServer<VersionStartup>(out var loggerFactory, out var server, $"{nameof(ClientUsingNewCallWithNewProtocol)}_{transportType}"))
{ {
var httpConnectionFactory = new HttpConnectionFactory(Options.Create(new HttpConnectionOptions var httpConnectionFactory = new HttpConnectionFactory(Options.Create(new HttpConnectionOptions
{ {
Url = new Uri(ServerFixture.Url + "/version"), Url = new Uri(server.Url + "/version"),
Transports = transportType Transports = transportType
}), loggerFactory); }), loggerFactory);
var tcs = new TaskCompletionSource<object>(); var tcs = new TaskCompletionSource<object>();
@ -168,11 +166,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
return writeContext.LoggerName == typeof(HubConnection).FullName; return writeContext.LoggerName == typeof(HubConnection).FullName;
} }
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, $"{nameof(ClientWithUnsupportedProtocolVersionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<VersionStartup>(out var loggerFactory, out var server, LogLevel.Trace, $"{nameof(ClientWithUnsupportedProtocolVersionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors))
{ {
var connectionBuilder = new HubConnectionBuilder() var connectionBuilder = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(ServerFixture.Url + "/version", transportType); .WithUrl(server.Url + "/version", transportType);
connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(int.MaxValue)); connectionBuilder.Services.AddSingleton<IHubProtocol>(new VersionedJsonHubProtocol(int.MaxValue));
var connection = connectionBuilder.Build(); var connection = connectionBuilder.Build();

View File

@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
public class RedisServerFixture<TStartup> : IDisposable public class RedisServerFixture<TStartup> : IDisposable
where TStartup : class where TStartup : class
{ {
public ServerFixture<TStartup> FirstServer { get; private set; } public InProcessTestServer<TStartup> FirstServer { get; private set; }
public ServerFixture<TStartup> SecondServer { get; private set; } public InProcessTestServer<TStartup> SecondServer { get; private set; }
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
SecondServer = StartServer(); SecondServer = StartServer();
} }
private ServerFixture<TStartup> StartServer() private InProcessTestServer<TStartup> StartServer()
{ {
try try
{ {
return new ServerFixture<TStartup>(_loggerFactory); return new InProcessTestServer<TStartup>(_loggerFactory);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -11,8 +11,8 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
public class RedisServerFixture<TStartup> : IDisposable public class RedisServerFixture<TStartup> : IDisposable
where TStartup : class where TStartup : class
{ {
public ServerFixture<TStartup> FirstServer { get; private set; } public InProcessTestServer<TStartup> FirstServer { get; private set; }
public ServerFixture<TStartup> SecondServer { get; private set; } public InProcessTestServer<TStartup> SecondServer { get; private set; }
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests
SecondServer = StartServer(); SecondServer = StartServer();
} }
private ServerFixture<TStartup> StartServer() private InProcessTestServer<TStartup> StartServer()
{ {
try try
{ {
return new ServerFixture<TStartup>(_loggerFactory); return new InProcessTestServer<TStartup>(_loggerFactory);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -2,26 +2,20 @@
// 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; using System;
using System.Net.Http; using System.Collections.Generic;
using System.Net.WebSockets;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Logging.Testing;
using Xunit.Abstractions; using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
public class VerifiableServerLoggedTest : VerifiableLoggedTest public class FunctionalTestBase : VerifiableLoggedTest
{ {
private readonly Func<WriteContext, bool> _globalExpectedErrorsFilter; private readonly Func<WriteContext, bool> _globalExpectedErrorsFilter;
public ServerFixture ServerFixture { get; } public FunctionalTestBase(ITestOutputHelper output) : base(output)
public VerifiableServerLoggedTest(ServerFixture serverFixture, ITestOutputHelper output) : base(output)
{ {
ServerFixture = serverFixture;
// Suppress errors globally here // Suppress errors globally here
_globalExpectedErrorsFilter = (writeContext) => false; _globalExpectedErrorsFilter = (writeContext) => false;
} }
@ -44,25 +38,35 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}; };
} }
public override IDisposable StartVerifiableLog(out ILoggerFactory loggerFactory, LogLevel minLogLevel, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) public IDisposable StartServer<T>(out ILoggerFactory loggerFactory, out InProcessTestServer<T> testServer, LogLevel minLogLevel, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) where T : class
{ {
var disposable = base.StartVerifiableLog(out loggerFactory, minLogLevel, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter)); var disposable = base.StartVerifiableLog(out loggerFactory, minLogLevel, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
return new ServerLogScope(ServerFixture, loggerFactory, disposable); testServer = new InProcessTestServer<T>(loggerFactory);
return new MultiDisposable(testServer, disposable);
} }
public override IDisposable StartVerifiableLog(out ILoggerFactory loggerFactory, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) public IDisposable StartServer<T>(out ILoggerFactory loggerFactory, out InProcessTestServer<T> testServer, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null) where T : class
{ {
var disposable = base.StartVerifiableLog(out loggerFactory, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter)); var disposable = base.StartVerifiableLog(out loggerFactory, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
return new ServerLogScope(ServerFixture, loggerFactory, disposable); testServer = new InProcessTestServer<T>(loggerFactory);
return new MultiDisposable(testServer, disposable);
} }
public override void Dispose() private class MultiDisposable : IDisposable
{ {
// Unit tests in a fixture reuse the server. List<IDisposable> _disposables;
// A small delay prevents server logging from a previous tests from showing up in the next test's logs public MultiDisposable(params IDisposable[] disposables)
// by giving the server time to finish any in-progress request logic. {
Thread.Sleep(TimeSpan.FromMilliseconds(100)); _disposables = new List<IDisposable>(disposables);
base.Dispose(); }
public void Dispose()
{
foreach (var disposable in _disposables)
{
disposable.Dispose();
}
}
} }
} }
} }

View File

@ -5,20 +5,17 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Logging.Testing;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
public abstract class ServerFixture : IDisposable public abstract class InProcessTestServer : IDisposable
{ {
internal abstract event Action<LogRecord> ServerLogged; internal abstract event Action<LogRecord> ServerLogged;
@ -29,7 +26,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public abstract void Dispose(); public abstract void Dispose();
} }
public class ServerFixture<TStartup> : ServerFixture public class InProcessTestServer<TStartup> : InProcessTestServer
where TStartup : class where TStartup : class
{ {
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
@ -51,19 +48,19 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public override string Url => _url; public override string Url => _url;
public ServerFixture() : this(loggerFactory: null) public InProcessTestServer() : this(loggerFactory: null)
{ {
} }
public ServerFixture(ILoggerFactory loggerFactory) public InProcessTestServer(ILoggerFactory loggerFactory)
{ {
_logSinkProvider = new LogSinkProvider(); _logSinkProvider = new LogSinkProvider();
if (loggerFactory == null) if (loggerFactory == null)
{ {
var testLog = AssemblyTestLog.ForAssembly(typeof(TStartup).Assembly); var testLog = AssemblyTestLog.ForAssembly(typeof(TStartup).Assembly);
_logToken = testLog.StartTestLog(null, $"{nameof(ServerFixture<TStartup>)}_{typeof(TStartup).Name}", _logToken = testLog.StartTestLog(null, $"{nameof(InProcessTestServer<TStartup>)}_{typeof(TStartup).Name}",
out _loggerFactory, nameof(ServerFixture)); out _loggerFactory, nameof(InProcessTestServer));
} }
else else
{ {
@ -72,7 +69,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
_loggerFactory = new WrappingLoggerFactory(_loggerFactory); _loggerFactory = new WrappingLoggerFactory(_loggerFactory);
_loggerFactory.AddProvider(_logSinkProvider); _loggerFactory.AddProvider(_logSinkProvider);
_logger = _loggerFactory.CreateLogger<ServerFixture<TStartup>>(); _logger = _loggerFactory.CreateLogger<InProcessTestServer<TStartup>>();
StartServer(); StartServer();
} }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{ {
public class ServerLogScope : IDisposable public class ServerLogScope : IDisposable
{ {
private readonly ServerFixture _serverFixture; private readonly InProcessTestServer _serverFixture;
private readonly ILoggerFactory _loggerFactory; private readonly ILoggerFactory _loggerFactory;
private readonly IDisposable _wrappedDisposable; private readonly IDisposable _wrappedDisposable;
private readonly ConcurrentDictionary<string, ILogger> _serverLoggers; private readonly ConcurrentDictionary<string, ILogger> _serverLoggers;
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private readonly object _lock; private readonly object _lock;
private bool _disposed; private bool _disposed;
public ServerLogScope(ServerFixture serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable) public ServerLogScope(InProcessTestServer serverFixture, ILoggerFactory loggerFactory, IDisposable wrappedDisposable)
{ {
_loggerFactory = loggerFactory; _loggerFactory = loggerFactory;
_serverFixture = serverFixture; _serverFixture = serverFixture;

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Net.Http; using System.Net.Http;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -27,26 +26,24 @@ using HttpConnectionOptions = Microsoft.AspNetCore.Http.Connections.Client.HttpC
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
// Disable running server tests in parallel so server logs can accurately be captured per test public class EndToEndTestsCollection : ICollectionFixture<InProcessTestServer<Startup>>
[CollectionDefinition(Name, DisableParallelization = true)]
public class EndToEndTestsCollection : ICollectionFixture<ServerFixture<Startup>>
{ {
public const string Name = nameof(EndToEndTestsCollection); public const string Name = nameof(EndToEndTestsCollection);
} }
[Collection(EndToEndTestsCollection.Name)] [Collection(EndToEndTestsCollection.Name)]
public class EndToEndTests : VerifiableServerLoggedTest public class EndToEndTests : FunctionalTestBase
{ {
public EndToEndTests(ServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(serverFixture, output) public EndToEndTests(ITestOutputHelper output) : base(output)
{ {
} }
[Fact] [Fact]
public async Task CanStartAndStopConnectionUsingDefaultTransport() public async Task CanStartAndStopConnectionUsingDefaultTransport()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer. // The test should connect to the server using WebSockets transport on Windows 8 and newer.
// On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server. // On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server.
var connection = new HttpConnection(new Uri(url), HttpTransports.All, loggerFactory); var connection = new HttpConnection(new Uri(url), HttpTransports.All, loggerFactory);
@ -64,9 +61,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport"; writeContext.EventId.Name == "ErrorStartingTransport";
} }
using (StartVerifiableLog(out var loggerFactory, expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var server, expectedErrorsFilter: ExpectedErrors))
{ {
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
// The test should connect to the server using WebSockets transport on Windows 8 and newer. // The test should connect to the server using WebSockets transport on Windows 8 and newer.
// On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server. // On Windows 7/2008R2 it should use ServerSentEvents transport to connect to the server.
@ -81,9 +78,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[MemberData(nameof(TransportTypes))] [MemberData(nameof(TransportTypes))]
public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType) public async Task CanStartAndStopConnectionUsingGivenTransport(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, minLogLevel: LogLevel.Trace, testName: $"CanStartAndStopConnectionUsingGivenTransport_{transportType}")) using (StartServer<Startup>(out var loggerFactory, out var server, minLogLevel: LogLevel.Trace, testName: $"CanStartAndStopConnectionUsingGivenTransport_{transportType}"))
{ {
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory); var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
await connection.StartAsync(TransferFormat.Text).OrTimeout(); await connection.StartAsync(TransferFormat.Text).OrTimeout();
await connection.DisposeAsync().OrTimeout(); await connection.DisposeAsync().OrTimeout();
@ -94,14 +91,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTest() public async Task WebSocketsTest()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
const string message = "Hello, World!"; const string message = "Hello, World!";
using (var ws = new ClientWebSocket()) using (var ws = new ClientWebSocket())
{ {
var socketUrl = ServerFixture.WebSocketsUrl + "/echo"; var socketUrl = server.WebSocketsUrl + "/echo";
logger.LogInformation("Connecting WebSocket to {socketUrl}", socketUrl); logger.LogInformation("Connecting WebSocket to {socketUrl}", socketUrl);
await ws.ConnectAsync(new Uri(socketUrl), CancellationToken.None).OrTimeout(); await ws.ConnectAsync(new Uri(socketUrl), CancellationToken.None).OrTimeout();
@ -132,14 +129,14 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsReceivesAndSendsPartialFramesTest() public async Task WebSocketsReceivesAndSendsPartialFramesTest()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
const string message = "Hello, World!"; const string message = "Hello, World!";
using (var ws = new ClientWebSocket()) using (var ws = new ClientWebSocket())
{ {
var socketUrl = ServerFixture.WebSocketsUrl + "/echo"; var socketUrl = server.WebSocketsUrl + "/echo";
logger.LogInformation("Connecting WebSocket to {socketUrl}", socketUrl); logger.LogInformation("Connecting WebSocket to {socketUrl}", socketUrl);
await ws.ConnectAsync(new Uri(socketUrl), CancellationToken.None).OrTimeout(); await ws.ConnectAsync(new Uri(socketUrl), CancellationToken.None).OrTimeout();
@ -171,10 +168,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task HttpRequestsNotSentWhenWebSocketsTransportRequestedAndSkipNegotiationSet() public async Task HttpRequestsNotSentWhenWebSocketsTransportRequestedAndSkipNegotiationSet()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
var mockHttpHandler = new Mock<HttpMessageHandler>(); var mockHttpHandler = new Mock<HttpMessageHandler>();
mockHttpHandler.Protected() mockHttpHandler.Protected()
@ -221,10 +218,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(HttpTransportType.ServerSentEvents)] [InlineData(HttpTransportType.ServerSentEvents)]
public async Task HttpConnectionThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets(HttpTransportType transportType) public async Task HttpConnectionThrowsIfSkipNegotiationSetAndTransportIsNotWebSockets(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
var mockHttpHandler = new Mock<HttpMessageHandler>(); var mockHttpHandler = new Mock<HttpMessageHandler>();
mockHttpHandler.Protected() mockHttpHandler.Protected()
@ -263,13 +260,13 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[MemberData(nameof(TransportTypesAndTransferFormats))] [MemberData(nameof(TransportTypesAndTransferFormats))]
public async Task ConnectionCanSendAndReceiveMessages(HttpTransportType transportType, TransferFormat requestedTransferFormat) public async Task ConnectionCanSendAndReceiveMessages(HttpTransportType transportType, TransferFormat requestedTransferFormat)
{ {
using (StartVerifiableLog(out var loggerFactory, minLogLevel: LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}_{requestedTransferFormat.ToString()}")) using (StartServer<Startup>(out var loggerFactory, out var server, minLogLevel: LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}_{requestedTransferFormat.ToString()}"))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
const string message = "Major Key"; const string message = "Major Key";
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory); var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
try try
{ {
@ -327,11 +324,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[MemberData(nameof(MessageSizesData))] [MemberData(nameof(MessageSizesData))]
public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(string message) public async Task ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport(string message)
{ {
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport_{message.Length}")) using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, testName: $"ConnectionCanSendAndReceiveDifferentMessageSizesWebSocketsTransport_{message.Length}"))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/echo"; var url = server.Url + "/echo";
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory); var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory);
try try
@ -375,11 +372,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/auth"; var url = server.Url + "/auth";
var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory); var connection = new HttpConnection(new Uri(url), HttpTransportType.WebSockets, loggerFactory);
var exception = await Assert.ThrowsAsync<HttpRequestException>(() => connection.StartAsync(TransferFormat.Binary).OrTimeout()); var exception = await Assert.ThrowsAsync<HttpRequestException>(() => connection.StartAsync(TransferFormat.Binary).OrTimeout());
@ -398,11 +395,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorStartingTransport"; writeContext.EventId.Name == "ErrorStartingTransport";
} }
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, expectedErrorsFilter: ExpectedErrors))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/auth"; var url = server.Url + "/auth";
var options = new HttpConnectionOptions var options = new HttpConnectionOptions
{ {
Url = new Uri(url), Url = new Uri(url),
@ -427,11 +424,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
writeContext.EventId.Name == "ErrorWithNegotiation"; writeContext.EventId.Name == "ErrorWithNegotiation";
} }
using (StartVerifiableLog(out var loggerFactory, LogLevel.Trace, testName: $"{nameof(UnauthorizedConnectionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors)) using (StartServer<Startup>(out var loggerFactory, out var server, LogLevel.Trace, testName: $"{nameof(UnauthorizedConnectionDoesNotConnect)}_{transportType}", expectedErrorsFilter: ExpectedErrors))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/auth"; var url = server.Url + "/auth";
var connection = new HttpConnection(new Uri(url), transportType, loggerFactory); var connection = new HttpConnection(new Uri(url), transportType, loggerFactory);
try try
@ -484,11 +481,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTransportType transportType) private async Task ServerClosesConnectionWithErrorIfHubCannotBeCreated(HttpTransportType transportType)
{ {
using (StartVerifiableLog(out var loggerFactory, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}")) using (StartServer<Startup>(out var loggerFactory, out var server, testName: $"ConnectionCanSendAndReceiveMessages_{transportType.ToString()}"))
{ {
var logger = loggerFactory.CreateLogger<EndToEndTests>(); var logger = loggerFactory.CreateLogger<EndToEndTests>();
var url = ServerFixture.Url + "/uncreatable"; var url = server.Url + "/uncreatable";
var connection = new HubConnectionBuilder() var connection = new HubConnectionBuilder()
.WithLoggerFactory(loggerFactory) .WithLoggerFactory(loggerFactory)
.WithUrl(url, transportType) .WithUrl(url, transportType)

View File

@ -20,9 +20,9 @@ using Xunit.Abstractions;
namespace Microsoft.AspNetCore.SignalR.Tests namespace Microsoft.AspNetCore.SignalR.Tests
{ {
[Collection(EndToEndTestsCollection.Name)] [Collection(EndToEndTestsCollection.Name)]
public class WebSocketsTransportTests : VerifiableServerLoggedTest public class WebSocketsTransportTests : FunctionalTestBase
{ {
public WebSocketsTransportTests(ServerFixture<Startup> serverFixture, ITestOutputHelper output) : base(serverFixture, output) public WebSocketsTransportTests(ITestOutputHelper output) : base(output)
{ {
} }
@ -57,10 +57,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped() public async Task WebSocketsTransportStopsSendAndReceiveLoopsWhenTransportIsStopped()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/echo"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
TransferFormat.Binary).OrTimeout(); TransferFormat.Binary).OrTimeout();
await webSocketsTransport.StopAsync().OrTimeout(); await webSocketsTransport.StopAsync().OrTimeout();
await webSocketsTransport.Running.OrTimeout(); await webSocketsTransport.Running.OrTimeout();
@ -71,10 +71,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsUserAgent() public async Task WebSocketsTransportSendsUserAgent()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/httpheader"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
TransferFormat.Binary).OrTimeout(); TransferFormat.Binary).OrTimeout();
await webSocketsTransport.Output.WriteAsync(Encoding.UTF8.GetBytes("User-Agent")); await webSocketsTransport.Output.WriteAsync(Encoding.UTF8.GetBytes("User-Agent"));
@ -99,10 +99,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportSendsXRequestedWithHeader() public async Task WebSocketsTransportSendsXRequestedWithHeader()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/httpheader"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/httpheader"),
TransferFormat.Binary).OrTimeout(); TransferFormat.Binary).OrTimeout();
await webSocketsTransport.Output.WriteAsync(Encoding.UTF8.GetBytes("X-Requested-With")); await webSocketsTransport.Output.WriteAsync(Encoding.UTF8.GetBytes("X-Requested-With"));
@ -122,10 +122,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[WebSocketsSupportedCondition] [WebSocketsSupportedCondition]
public async Task WebSocketsTransportStopsWhenConnectionChannelClosed() public async Task WebSocketsTransportStopsWhenConnectionChannelClosed()
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/echo"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
TransferFormat.Binary); TransferFormat.Binary);
webSocketsTransport.Output.Complete(); webSocketsTransport.Output.Complete();
await webSocketsTransport.Running.OrTimeout(TimeSpan.FromSeconds(10)); await webSocketsTransport.Running.OrTimeout(TimeSpan.FromSeconds(10));
@ -138,10 +138,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)] [InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat) public async Task WebSocketsTransportStopsWhenConnectionClosedByTheServer(TransferFormat transferFormat)
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/echoAndClose"), transferFormat); await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echoAndClose"), transferFormat);
await webSocketsTransport.Output.WriteAsync(new byte[] { 0x42 }); await webSocketsTransport.Output.WriteAsync(new byte[] { 0x42 });
@ -160,11 +160,11 @@ namespace Microsoft.AspNetCore.SignalR.Tests
[InlineData(TransferFormat.Binary)] [InlineData(TransferFormat.Binary)]
public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat) public async Task WebSocketsTransportSetsTransferFormat(TransferFormat transferFormat)
{ {
using (StartVerifiableLog(out var loggerFactory)) using (StartServer<Startup>(out var loggerFactory, out var server))
{ {
var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null); var webSocketsTransport = new WebSocketsTransport(httpConnectionOptions: null, loggerFactory: loggerFactory, accessTokenProvider: null);
await webSocketsTransport.StartAsync(new Uri(ServerFixture.WebSocketsUrl + "/echo"), await webSocketsTransport.StartAsync(new Uri(server.WebSocketsUrl + "/echo"),
transferFormat).OrTimeout(); transferFormat).OrTimeout();
await webSocketsTransport.StopAsync().OrTimeout(); await webSocketsTransport.StopAsync().OrTimeout();