Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 9732d75

Browse files
committed
Added tests
1 parent 4f4850a commit 9732d75

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

test/Microsoft.AspNetCore.Server.WebListener.FunctionalTests/ResponseBodyTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ public async Task ResponseBody_WriteNoHeaders_SetsChunked()
3636
}
3737
}
3838

39+
[ConditionalTheory]
40+
[InlineData(true)]
41+
[InlineData(false)]
42+
public async Task ResponseBody_WriteNoHeaders_SetsChunked_LargeBody(bool enableKernelBuffering)
43+
{
44+
const int WriteSize = 1024 * 1024;
45+
const int NumWrites = 32;
46+
47+
string address;
48+
using (Utilities.CreateHttpServer(
49+
baseAddress: out address,
50+
app: httpContext =>
51+
{
52+
for (int i = 0; i < NumWrites - 1; i++)
53+
{
54+
httpContext.Response.Body.Write(new byte[WriteSize], 0, WriteSize);
55+
}
56+
return httpContext.Response.Body.WriteAsync(new byte[WriteSize], 0, WriteSize);
57+
},
58+
enableKernelBuffering: enableKernelBuffering))
59+
{
60+
var response = await SendRequestAsync(address);
61+
Assert.Equal(200, (int)response.StatusCode);
62+
Assert.Equal(new Version(1, 1), response.Version);
63+
IEnumerable<string> ignored;
64+
Assert.False(response.Content.Headers.TryGetValues("content-length", out ignored), "Content-Length");
65+
Assert.True(response.Headers.TransferEncodingChunked.HasValue, "Chunked");
66+
67+
var bytes = await response.Content.ReadAsByteArrayAsync();
68+
Assert.Equal(WriteSize * NumWrites, bytes.Length);
69+
Assert.True(bytes.All(b => b == 0));
70+
}
71+
}
72+
3973
[ConditionalFact]
4074
public async Task ResponseBody_WriteNoHeadersAndFlush_DefaultsToChunked()
4175
{

test/Microsoft.AspNetCore.Server.WebListener.FunctionalTests/Utilities.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,46 @@ internal static class Utilities
2121
private static int NextPort = BasePort;
2222
private static object PortLock = new object();
2323

24-
internal static IServer CreateHttpServer(out string baseAddress, RequestDelegate app)
24+
internal static IServer CreateHttpServer(out string baseAddress, RequestDelegate app, bool enableKernelBuffering = false)
2525
{
2626
string root;
27-
return CreateDynamicHttpServer(string.Empty, AuthenticationSchemes.None, true, out root, out baseAddress, app);
27+
return CreateDynamicHttpServer(
28+
basePath: string.Empty,
29+
authType: AuthenticationSchemes.None,
30+
allowAnonymous: true,
31+
enableKernelBuffering: enableKernelBuffering,
32+
root: out root,
33+
baseAddress: out baseAddress,
34+
app: app);
2835
}
2936

3037
internal static IServer CreateHttpServerReturnRoot(string path, out string root, RequestDelegate app)
3138
{
3239
string baseAddress;
33-
return CreateDynamicHttpServer(path, AuthenticationSchemes.None, true, out root, out baseAddress, app);
40+
return CreateDynamicHttpServer(
41+
basePath: path,
42+
authType: AuthenticationSchemes.None,
43+
allowAnonymous: true,
44+
enableKernelBuffering: false,
45+
root: out root,
46+
baseAddress: out baseAddress,
47+
app: app);
3448
}
3549

3650
internal static IServer CreateHttpAuthServer(AuthenticationSchemes authType, bool allowAnonymous, out string baseAddress, RequestDelegate app)
3751
{
3852
string root;
39-
return CreateDynamicHttpServer(string.Empty, authType, allowAnonymous, out root, out baseAddress, app);
53+
return CreateDynamicHttpServer(
54+
basePath: string.Empty,
55+
authType: authType,
56+
allowAnonymous: allowAnonymous,
57+
enableKernelBuffering: false,
58+
root: out root,
59+
baseAddress: out baseAddress,
60+
app: app);
4061
}
4162

42-
internal static IServer CreateDynamicHttpServer(string basePath, AuthenticationSchemes authType, bool allowAnonymous, out string root, out string baseAddress, RequestDelegate app)
63+
internal static IServer CreateDynamicHttpServer(string basePath, AuthenticationSchemes authType, bool allowAnonymous, bool enableKernelBuffering, out string root, out string baseAddress, RequestDelegate app)
4364
{
4465
lock (PortLock)
4566
{
@@ -55,6 +76,7 @@ internal static IServer CreateDynamicHttpServer(string basePath, AuthenticationS
5576
server.Features.Get<IServerAddressesFeature>().Addresses.Add(baseAddress);
5677
server.Listener.Settings.Authentication.Schemes = authType;
5778
server.Listener.Settings.Authentication.AllowAnonymous = allowAnonymous;
79+
server.Listener.Settings.EnableKernelResponseBuffering = enableKernelBuffering;
5880
try
5981
{
6082
server.Start(new DummyApplication(app));

0 commit comments

Comments
 (0)