Don't hardcode fixed size for GetMemory in ChunkedTests
This commit is contained in:
parent
b571246c93
commit
6b7e821913
|
|
@ -469,6 +469,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ChunksWithGetMemoryLargeWriteBeforeFirstFlush()
|
public async Task ChunksWithGetMemoryLargeWriteBeforeFirstFlush()
|
||||||
{
|
{
|
||||||
|
var length = new IntAsRef();
|
||||||
|
var semaphore = new SemaphoreSlim(initialCount: 0);
|
||||||
var testContext = new TestServiceContext(LoggerFactory);
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
|
|
@ -476,7 +478,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
var response = httpContext.Response;
|
var response = httpContext.Response;
|
||||||
await response.StartAsync();
|
await response.StartAsync();
|
||||||
|
|
||||||
var memory = response.BodyPipe.GetMemory(); // This will return 4089
|
var memory = response.BodyPipe.GetMemory();
|
||||||
|
length.Value = memory.Length;
|
||||||
|
semaphore.Release();
|
||||||
|
|
||||||
var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
|
var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
|
||||||
fisrtPartOfResponse.CopyTo(memory);
|
fisrtPartOfResponse.CopyTo(memory);
|
||||||
response.BodyPipe.Advance(memory.Length);
|
response.BodyPipe.Advance(memory.Length);
|
||||||
|
|
@ -496,13 +501,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
"Host: ",
|
"Host: ",
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
|
|
||||||
|
// Wait for length to be set
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
|
||||||
await connection.Receive(
|
await connection.Receive(
|
||||||
"HTTP/1.1 200 OK",
|
"HTTP/1.1 200 OK",
|
||||||
$"Date: {testContext.DateHeaderValue}",
|
$"Date: {testContext.DateHeaderValue}",
|
||||||
"Transfer-Encoding: chunked",
|
"Transfer-Encoding: chunked",
|
||||||
"",
|
"",
|
||||||
"ff9",
|
length.Value.ToString("x"),
|
||||||
new string('a', 4089),
|
new string('a', length.Value),
|
||||||
"6",
|
"6",
|
||||||
"World!",
|
"World!",
|
||||||
"0",
|
"0",
|
||||||
|
|
@ -517,6 +526,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ChunksWithGetMemoryWithInitialFlushWorks()
|
public async Task ChunksWithGetMemoryWithInitialFlushWorks()
|
||||||
{
|
{
|
||||||
|
var length = new IntAsRef();
|
||||||
|
var semaphore = new SemaphoreSlim(initialCount: 0);
|
||||||
var testContext = new TestServiceContext(LoggerFactory);
|
var testContext = new TestServiceContext(LoggerFactory);
|
||||||
|
|
||||||
using (var server = new TestServer(async httpContext =>
|
using (var server = new TestServer(async httpContext =>
|
||||||
|
|
@ -525,7 +536,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
|
|
||||||
await response.BodyPipe.FlushAsync();
|
await response.BodyPipe.FlushAsync();
|
||||||
|
|
||||||
var memory = response.BodyPipe.GetMemory(); // This will return 4089
|
var memory = response.BodyPipe.GetMemory();
|
||||||
|
length.Value = memory.Length;
|
||||||
|
semaphore.Release();
|
||||||
|
|
||||||
var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
|
var fisrtPartOfResponse = Encoding.ASCII.GetBytes(new string('a', memory.Length));
|
||||||
fisrtPartOfResponse.CopyTo(memory);
|
fisrtPartOfResponse.CopyTo(memory);
|
||||||
response.BodyPipe.Advance(memory.Length);
|
response.BodyPipe.Advance(memory.Length);
|
||||||
|
|
@ -545,13 +559,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
"Host: ",
|
"Host: ",
|
||||||
"",
|
"",
|
||||||
"");
|
"");
|
||||||
|
|
||||||
|
// Wait for length to be set
|
||||||
|
await semaphore.WaitAsync();
|
||||||
|
|
||||||
await connection.Receive(
|
await connection.Receive(
|
||||||
"HTTP/1.1 200 OK",
|
"HTTP/1.1 200 OK",
|
||||||
$"Date: {testContext.DateHeaderValue}",
|
$"Date: {testContext.DateHeaderValue}",
|
||||||
"Transfer-Encoding: chunked",
|
"Transfer-Encoding: chunked",
|
||||||
"",
|
"",
|
||||||
"ff9",
|
length.Value.ToString("x"),
|
||||||
new string('a', 4089),
|
new string('a', length.Value),
|
||||||
"6",
|
"6",
|
||||||
"World!",
|
"World!",
|
||||||
"0",
|
"0",
|
||||||
|
|
@ -830,6 +848,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||||
await server.StopAsync();
|
await server.StopAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class IntAsRef
|
||||||
|
{
|
||||||
|
public int Value { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue