Fix flakiness in ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate (#1955).
This commit is contained in:
parent
dc9ed60465
commit
a145734d43
|
|
@ -2444,15 +2444,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalFact]
|
[Fact]
|
||||||
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "Flaky test (https://github.com/aspnet/KestrelHttpServer/issues/1955)")]
|
public void ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate()
|
||||||
public async Task ConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate()
|
|
||||||
{
|
{
|
||||||
var chunkSize = 64 * 1024;
|
var chunkSize = 64 * 1024;
|
||||||
var chunks = 128;
|
var chunks = 128;
|
||||||
|
var responseSize = chunks * chunkSize;
|
||||||
|
|
||||||
|
var requestAborted = new ManualResetEventSlim();
|
||||||
var messageLogged = new ManualResetEventSlim();
|
var messageLogged = new ManualResetEventSlim();
|
||||||
|
|
||||||
var mockKestrelTrace = new Mock<IKestrelTrace>();
|
var mockKestrelTrace = new Mock<IKestrelTrace>();
|
||||||
mockKestrelTrace
|
mockKestrelTrace
|
||||||
.Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()))
|
.Setup(trace => trace.ResponseMininumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()))
|
||||||
|
|
@ -2471,16 +2471,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var aborted = new ManualResetEventSlim();
|
|
||||||
|
|
||||||
using (var server = new TestServer(async context =>
|
using (var server = new TestServer(async context =>
|
||||||
{
|
{
|
||||||
context.RequestAborted.Register(() =>
|
context.RequestAborted.Register(() => requestAborted.Set());
|
||||||
{
|
|
||||||
aborted.Set();
|
|
||||||
});
|
|
||||||
|
|
||||||
context.Response.ContentLength = chunks * chunkSize;
|
context.Response.ContentLength = responseSize;
|
||||||
|
|
||||||
for (var i = 0; i < chunks; i++)
|
for (var i = 0; i < chunks; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -2488,29 +2483,36 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}, testContext))
|
}, testContext))
|
||||||
{
|
{
|
||||||
using (var connection = server.CreateConnection())
|
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||||
{
|
{
|
||||||
await connection.Send(
|
socket.ReceiveBufferSize = 1;
|
||||||
"GET / HTTP/1.1",
|
|
||||||
"Host:",
|
|
||||||
"",
|
|
||||||
"");
|
|
||||||
|
|
||||||
Assert.True(aborted.Wait(TimeSpan.FromSeconds(60)));
|
socket.Connect(new IPEndPoint(IPAddress.Loopback, server.Port));
|
||||||
|
socket.Send(Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nHost: \r\n\r\n"));
|
||||||
|
|
||||||
await connection.Receive(
|
Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(60)), "The expected message was not logged within the timeout period.");
|
||||||
"HTTP/1.1 200 OK",
|
Assert.True(requestAborted.Wait(TimeSpan.FromSeconds(60)), "The request was not aborted within the timeout period.");
|
||||||
"");
|
|
||||||
await connection.ReceiveStartsWith("Date: ");
|
|
||||||
await connection.Receive(
|
|
||||||
$"Content-Length: {chunks * chunkSize}",
|
|
||||||
"",
|
|
||||||
"");
|
|
||||||
|
|
||||||
await Assert.ThrowsAsync<EqualException>(async () => await connection.ReceiveForcedEnd(
|
var totalReceived = 0;
|
||||||
new string('a', chunks * chunkSize)));
|
var received = 0;
|
||||||
|
|
||||||
Assert.True(messageLogged.Wait(TimeSpan.FromSeconds(10)));
|
try
|
||||||
|
{
|
||||||
|
var buffer = new byte[chunkSize];
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
received = socket.Receive(buffer);
|
||||||
|
totalReceived += received;
|
||||||
|
} while (received > 0 && totalReceived < responseSize);
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
// Socket.Receive could throw, and that is fine
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since we expect writes to be cut off by the rate control, we should never see the entire response
|
||||||
|
Assert.NotEqual(responseSize, totalReceived);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue