Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit c41b27d

Browse files
committed
Make test more robust, by continuing to wait if client has not yet uploaded the expected number of bytes.
- If test fails, it may now wait forever instead of throwing a nice assert. - However, this change should make the test more robust on slow machines.
1 parent 139b8b2 commit c41b27d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxInputBufferLengthTests.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,32 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool sendContentLength
114114

115115
if (expectPause)
116116
{
117-
// Block until the send task has gone a while without writing bytes, which likely means
118-
// the server input buffer is full.
119-
while ((DateTime.Now - lastBytesWritten) < bytesWrittenTimeout)
120-
{
121-
await Task.Delay(bytesWrittenPollingInterval);
122-
}
123-
124-
// Verify the number of bytes written before the client was paused.
125-
//
126117
// The minimum is (maxRequestBufferSize - maxSendSize + 1), since if bytesWritten is
127118
// (maxRequestBufferSize - maxSendSize) or smaller, the client should be able to
128119
// complete another send.
129-
//
120+
var minimumExpectedBytesWritten = maxRequestBufferSize.Value - maxSendSize + 1;
121+
130122
// The maximum is harder to determine, since there can be OS-level buffers in both the client
131123
// and server, which allow the client to send more than maxRequestBufferSize before getting
132124
// paused. We assume the combined buffers are smaller than the difference between
133125
// data.Length and maxRequestBufferSize.
134-
Assert.InRange(bytesWritten, maxRequestBufferSize.Value - maxSendSize + 1, data.Length - 1);
126+
var maximumExpectedBytesWritten = data.Length - 1;
127+
128+
// Block until the send task has gone a while without writing bytes AND
129+
// the bytes written exceeds the minimum expected. This indicates the server buffer
130+
// is full.
131+
//
132+
// If the send task is paused before the expected number of bytes have been
133+
// written, keep waiting since the pause may have been caused by something else
134+
// like a slow machine.
135+
while ((DateTime.Now - lastBytesWritten) < bytesWrittenTimeout ||
136+
bytesWritten < minimumExpectedBytesWritten)
137+
{
138+
await Task.Delay(bytesWrittenPollingInterval);
139+
}
140+
141+
// Verify the number of bytes written before the client was paused.
142+
Assert.InRange(bytesWritten, minimumExpectedBytesWritten, maximumExpectedBytesWritten);
135143

136144
// Tell server to start reading request body
137145
startReadingRequestBody.Set();

0 commit comments

Comments
 (0)