Skip to content

Commit 50299cb

Browse files
authored
1 parent c950e71 commit 50299cb

File tree

7 files changed

+33
-140
lines changed

7 files changed

+33
-140
lines changed

ServerTests.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26228.10
3+
VisualStudioVersion = 15.0.26403.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49AB8AAA-8160-48DF-A18B-78F51E54E02A}"
66
ProjectSection(SolutionItems) = preProject

test/ServerComparison.FunctionalTests/HelloWorldTest.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Runtime.CompilerServices;
77
using System.Threading.Tasks;
88
using Microsoft.AspNetCore.Server.IntegrationTesting;
9+
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
910
using Microsoft.AspNetCore.Testing.xunit;
1011
using Microsoft.DotNet.PlatformAbstractions;
1112
using Microsoft.Extensions.Logging;
@@ -15,13 +16,10 @@
1516

1617
namespace ServerComparison.FunctionalTests
1718
{
18-
public class HelloWorldTests
19+
public class HelloWorldTests : LoggedTest
1920
{
20-
private readonly ITestOutputHelper _output;
21-
22-
public HelloWorldTests(ITestOutputHelper output)
21+
public HelloWorldTests(ITestOutputHelper output) : base(output)
2322
{
24-
_output = output;
2523
}
2624

2725
// Tests disabled on x86 because of https://github.com/aspnet/Hosting/issues/601
@@ -60,13 +58,10 @@ public Task HelloWorld_Nginx(ServerType serverType, RuntimeFlavor runtimeFlavor,
6058
public async Task HelloWorld(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType, [CallerMemberName] string testName = null)
6159
{
6260
testName = $"{testName}_{serverType}_{runtimeFlavor}_{architecture}_{applicationType}";
63-
var loggerFactory = TestLoggingUtilities.SetUpLogging<HelloWorldTests>(_output, testName);
64-
var logger = loggerFactory.CreateLogger("TestHarness");
65-
Console.WriteLine($"Starting test: {testName}");
66-
logger.LogInformation("Starting test: {testName}", testName);
67-
68-
using (logger.BeginScope("HelloWorld"))
61+
using (StartLog(out var loggerFactory, testName))
6962
{
63+
var logger = loggerFactory.CreateLogger("HelloWorld");
64+
7065
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
7166
{
7267
EnvironmentName = "HelloWorld", // Will pick the Start class named 'StartupHelloWorld',
@@ -84,13 +79,11 @@ public async Task HelloWorld(ServerType serverType, RuntimeFlavor runtimeFlavor,
8479
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
8580
{
8681
var deploymentResult = await deployer.DeployAsync();
87-
var httpClientHandler = new HttpClientHandler();
88-
var httpClient = new HttpClient(new LoggingHandler(loggerFactory, httpClientHandler)) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
8982

9083
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
9184
var response = await RetryHelper.RetryRequest(() =>
9285
{
93-
return httpClient.GetAsync(string.Empty);
86+
return deploymentResult.HttpClient.GetAsync(string.Empty);
9487
}, logger, deploymentResult.HostShutdownToken);
9588

9689
var responseText = await response.Content.ReadAsStringAsync();
@@ -106,9 +99,6 @@ public async Task HelloWorld(ServerType serverType, RuntimeFlavor runtimeFlavor,
10699
}
107100
}
108101
}
109-
110-
Console.WriteLine($"Finished test: {testName}");
111-
logger.LogInformation("Finished test: {testName}", testName);
112102
}
113103
}
114104
}

test/ServerComparison.FunctionalTests/LoggingHandler.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/ServerComparison.FunctionalTests/NtlmAuthenticationTest.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.CompilerServices;
99
using System.Threading.Tasks;
1010
using Microsoft.AspNetCore.Server.IntegrationTesting;
11+
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
1112
using Microsoft.AspNetCore.Testing.xunit;
1213
using Microsoft.DotNet.PlatformAbstractions;
1314
using Microsoft.Extensions.Logging;
@@ -17,13 +18,10 @@
1718

1819
namespace ServerComparison.FunctionalTests
1920
{
20-
public class NtlmAuthenticationTests
21+
public class NtlmAuthenticationTests : LoggedTest
2122
{
22-
private readonly ITestOutputHelper _output;
23-
24-
public NtlmAuthenticationTests(ITestOutputHelper output)
23+
public NtlmAuthenticationTests(ITestOutputHelper output) : base(output)
2524
{
26-
_output = output;
2725
}
2826

2927
[ConditionalTheory, Trait("ServerComparison.FunctionalTests", "ServerComparison.FunctionalTests")]
@@ -38,13 +36,10 @@ public NtlmAuthenticationTests(ITestOutputHelper output)
3836
public async Task NtlmAuthentication(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType)
3937
{
4038
var testName = $"NtlmAuthentication_{serverType}_{runtimeFlavor}_{architecture}_{applicationType}";
41-
var loggerFactory = TestLoggingUtilities.SetUpLogging<HelloWorldTests>(_output, testName);
42-
var logger = loggerFactory.CreateLogger("TestHarness");
43-
Console.WriteLine($"Starting test: {testName}");
44-
logger.LogInformation("Starting test: {testName}", testName);
45-
46-
using (logger.BeginScope("NtlmAuthenticationTest"))
39+
using (StartLog(out var loggerFactory, testName))
4740
{
41+
var logger = loggerFactory.CreateLogger("NtlmAuthenticationTest");
42+
4843
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
4944
{
5045
EnvironmentName = "NtlmAuthentication", // Will pick the Start class named 'StartupNtlmAuthentication'
@@ -62,8 +57,7 @@ public async Task NtlmAuthentication(ServerType serverType, RuntimeFlavor runtim
6257
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
6358
{
6459
var deploymentResult = await deployer.DeployAsync();
65-
var httpClientHandler = new HttpClientHandler();
66-
var httpClient = new HttpClient(new LoggingHandler(loggerFactory, httpClientHandler)) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
60+
var httpClient = deploymentResult.HttpClient;
6761

6862
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
6963
var response = await RetryHelper.RetryRequest(() =>
@@ -109,8 +103,9 @@ public async Task NtlmAuthentication(ServerType serverType, RuntimeFlavor runtim
109103
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
110104

111105
logger.LogInformation("Enabling Default Credentials");
112-
httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
113-
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
106+
107+
// Change the http client to one that uses default credentials
108+
httpClient = deploymentResult.CreateHttpClient(new HttpClientHandler() { UseDefaultCredentials = true });
114109

115110
logger.LogInformation("Testing /AutoForbid");
116111
response = await httpClient.GetAsync("/AutoForbid");
@@ -155,9 +150,6 @@ public async Task NtlmAuthentication(ServerType serverType, RuntimeFlavor runtim
155150
}
156151
}
157152
}
158-
159-
Console.WriteLine($"Finished test: {testName}");
160-
logger.LogInformation("Finished test: {testName}", testName);
161153
}
162154
}
163155
}

test/ServerComparison.FunctionalTests/ResponseCompressionTests.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Runtime.CompilerServices;
1212
using System.Threading.Tasks;
1313
using Microsoft.AspNetCore.Server.IntegrationTesting;
14+
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
1415
using Microsoft.AspNetCore.Testing.xunit;
1516
using Microsoft.DotNet.PlatformAbstractions;
1617
using Microsoft.Extensions.Logging;
@@ -21,15 +22,13 @@
2122

2223
namespace ServerComparison.FunctionalTests
2324
{
24-
public class ResponseCompressionTests
25+
public class ResponseCompressionTests : LoggedTest
2526
{
2627
// NGinx's default min size is 20 bytes
2728
private static readonly string HelloWorldBody = "Hello World;" + new string('a', 20);
28-
private readonly ITestOutputHelper _output;
2929

30-
public ResponseCompressionTests(ITestOutputHelper output)
30+
public ResponseCompressionTests(ITestOutputHelper output) : base(output)
3131
{
32-
_output = output;
3332
}
3433

3534
[ConditionalTheory]
@@ -127,13 +126,10 @@ public Task ResponseCompression_Nginx_AppAndHostCompression(ServerType serverTyp
127126
public async Task ResponseCompression(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, Func<HttpClient, ILogger, Task> scenario, ApplicationType applicationType, bool hostCompression, [CallerMemberName] string testName = null)
128127
{
129128
testName = $"{testName}_{serverType}_{runtimeFlavor}_{architecture}_{applicationType}";
130-
var loggerFactory = TestLoggingUtilities.SetUpLogging<ResponseCompressionTests>(_output, testName);
131-
var logger = loggerFactory.CreateLogger("TestHarness");
132-
Console.WriteLine($"Starting test: {testName}");
133-
logger.LogInformation("Starting test: {testName}", testName);
134-
135-
using (logger.BeginScope("ResponseCompression"))
129+
using (StartLog(out var loggerFactory, testName))
136130
{
131+
var logger = loggerFactory.CreateLogger("ResponseCompression");
132+
137133
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
138134
{
139135
EnvironmentName = "ResponseCompression",
@@ -155,7 +151,7 @@ public async Task ResponseCompression(ServerType serverType, RuntimeFlavor runti
155151
var deploymentResult = await deployer.DeployAsync();
156152
var httpClientHandler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None };
157153
Assert.True(httpClientHandler.SupportsAutomaticDecompression);
158-
var httpClient = new HttpClient(new LoggingHandler(loggerFactory, httpClientHandler)) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
154+
var httpClient = deploymentResult.CreateHttpClient(httpClientHandler);
159155

160156
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
161157
var response = await RetryHelper.RetryRequest(() =>
@@ -178,9 +174,6 @@ public async Task ResponseCompression(ServerType serverType, RuntimeFlavor runti
178174
await scenario(httpClient, logger);
179175
}
180176
}
181-
182-
Console.WriteLine($"Finished test: {testName}");
183-
logger.LogInformation("Finished test: {testName}", testName);
184177
}
185178

186179
private static async Task CheckNoCompressionAsync(HttpClient client, ILogger logger)

test/ServerComparison.FunctionalTests/ResponseTests.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.CompilerServices;
99
using System.Threading.Tasks;
1010
using Microsoft.AspNetCore.Server.IntegrationTesting;
11+
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
1112
using Microsoft.AspNetCore.Testing.xunit;
1213
using Microsoft.DotNet.PlatformAbstractions;
1314
using Microsoft.Extensions.Logging;
@@ -18,13 +19,10 @@
1819

1920
namespace ServerComparison.FunctionalTests
2021
{
21-
public class ResponseTests
22+
public class ResponseTests : LoggedTest
2223
{
23-
private readonly ITestOutputHelper _output;
24-
25-
public ResponseTests(ITestOutputHelper output)
24+
public ResponseTests(ITestOutputHelper output) : base(output)
2625
{
27-
_output = output;
2826
}
2927

3028
[ConditionalTheory]
@@ -165,13 +163,10 @@ public Task ResponseFormats_Kestrel_ManuallyChunkAndClose(ServerType serverType,
165163
public async Task ResponseFormats(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, Func<HttpClient, ILogger, Task> scenario, ApplicationType applicationType, [CallerMemberName] string testName = null)
166164
{
167165
testName = $"{testName}_{serverType}_{runtimeFlavor}_{architecture}_{applicationType}";
168-
var loggerFactory = TestLoggingUtilities.SetUpLogging<HelloWorldTests>(_output, testName);
169-
var logger = loggerFactory.CreateLogger("TestHarness");
170-
Console.WriteLine($"Starting test: {testName}");
171-
logger.LogInformation("Starting test: {testName}", testName);
172-
173-
using (logger.BeginScope("ResponseFormats"))
166+
using (StartLog(out var loggerFactory, testName))
174167
{
168+
var logger = loggerFactory.CreateLogger("ResponseFormats");
169+
175170
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
176171
{
177172
EnvironmentName = "Responses",
@@ -189,13 +184,11 @@ public async Task ResponseFormats(ServerType serverType, RuntimeFlavor runtimeFl
189184
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
190185
{
191186
var deploymentResult = await deployer.DeployAsync();
192-
var httpClientHandler = new HttpClientHandler();
193-
var httpClient = new HttpClient(new LoggingHandler(loggerFactory, httpClientHandler)) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
194187

195188
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
196189
var response = await RetryHelper.RetryRequest(() =>
197190
{
198-
return httpClient.GetAsync(string.Empty);
191+
return deploymentResult.HttpClient.GetAsync(string.Empty);
199192
}, logger, deploymentResult.HostShutdownToken);
200193

201194
var responseText = await response.Content.ReadAsStringAsync();
@@ -210,12 +203,9 @@ public async Task ResponseFormats(ServerType serverType, RuntimeFlavor runtimeFl
210203
throw;
211204
}
212205

213-
await scenario(httpClient, logger);
206+
await scenario(deploymentResult.HttpClient, logger);
214207
}
215208
}
216-
217-
Console.WriteLine($"Finished test: {testName}");
218-
logger.LogInformation("Finished test: {testName}", testName);
219209
}
220210

221211
private static async Task CheckContentLengthAsync(HttpClient client, ILogger logger)

test/ServerComparison.FunctionalTests/TestLoggingUtilities.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)