Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@ -875,6 +875,11 @@ namespace System.Net
}
writeStream.SetLength(copyBuffer.Length);
}
if (contentLength >= 0)
{
_progress.TotalBytesToReceive = contentLength;
}
using (writeStream)
using (Stream readStream = response.GetResponseStream())
@ -883,7 +888,7 @@ namespace System.Net
{
while (true)
{
int bytesRead = await readStream.ReadAsync(copyBuffer, 0, copyBuffer.Length).ConfigureAwait(false);
int bytesRead = await readStream.ReadAsync(new Memory<byte>(copyBuffer)).ConfigureAwait(false);
if (bytesRead == 0)
{
break;
@ -895,7 +900,7 @@ namespace System.Net
PostProgressChanged(asyncOp, _progress);
}
await writeStream.WriteAsync(copyBuffer, 0, bytesRead).ConfigureAwait(false);
await writeStream.WriteAsync(new ReadOnlyMemory<byte>(copyBuffer, 0, bytesRead)).ConfigureAwait(false);
}
}
@ -1005,7 +1010,7 @@ namespace System.Net
{
if (header != null)
{
await writeStream.WriteAsync(header, 0, header.Length).ConfigureAwait(false);
await writeStream.WriteAsync(new ReadOnlyMemory<byte>(header)).ConfigureAwait(false);
_progress.BytesSent += header.Length;
PostProgressChanged(asyncOp, _progress);
}
@ -1016,9 +1021,9 @@ namespace System.Net
{
while (true)
{
int bytesRead = await readStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
int bytesRead = await readStream.ReadAsync(new Memory<byte>(buffer)).ConfigureAwait(false);
if (bytesRead <= 0) break;
await writeStream.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
await writeStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, 0, bytesRead)).ConfigureAwait(false);
_progress.BytesSent += bytesRead;
PostProgressChanged(asyncOp, _progress);
@ -1034,7 +1039,7 @@ namespace System.Net
{
toWrite = chunkSize;
}
await writeStream.WriteAsync(buffer, pos, toWrite).ConfigureAwait(false);
await writeStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, pos, toWrite)).ConfigureAwait(false);
pos += toWrite;
_progress.BytesSent += toWrite;
PostProgressChanged(asyncOp, _progress);
@ -1043,7 +1048,7 @@ namespace System.Net
if (footer != null)
{
await writeStream.WriteAsync(footer, 0, footer.Length).ConfigureAwait(false);
await writeStream.WriteAsync(new ReadOnlyMemory<byte>(footer)).ConfigureAwait(false);
_progress.BytesSent += footer.Length;
PostProgressChanged(asyncOp, _progress);
}

View File

@ -19,7 +19,10 @@
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.cs">
<Link>Common\System\Net\Http\LoopbackServer.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Threading\Tasks\TaskTimeoutExtensions.cs">
<Link>Common\System\Threading\Tasks\TaskTimeoutExtensions.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@ -374,12 +374,7 @@ namespace System.Net.Tests
{
Task<string> download = wc.DownloadStringTaskAsync(url.ToString());
Assert.Null(wc.ResponseHeaders);
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: 0\r\n" +
"ArbitraryHeader: ArbitraryValue\r\n" +
"\r\n");
await server.AcceptConnectionSendResponseAndCloseAsync(additionalHeaders: "ArbitraryHeader: ArbitraryValue\r\n");
await download;
});
@ -430,11 +425,7 @@ namespace System.Net.Tests
{
Task<string> download = wc.DownloadStringTaskAsync(url.ToString());
Assert.Null(wc.ResponseHeaders);
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: 0\r\n" +
"\r\n");
await server.AcceptConnectionSendResponseAndCloseAsync();
await download;
});
}
@ -476,6 +467,8 @@ namespace System.Net.Tests
public abstract class WebClientTestBase
{
public const int TimeoutMilliseconds = 30 * 1000;
public static readonly object[][] EchoServers = System.Net.Test.Common.Configuration.Http.EchoServers;
const string ExpectedText =
"To be, or not to be, that is the question:" +
@ -520,12 +513,7 @@ namespace System.Net.Tests
}
Task<string> download = DownloadStringAsync(wc, url.ToString());
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: {ExpectedText.Length}\r\n" +
"\r\n" +
$"{ExpectedText}");
await server.AcceptConnectionSendResponseAndCloseAsync(content: ExpectedText);
Assert.Equal(ExpectedText, await download);
});
}
@ -541,14 +529,13 @@ namespace System.Net.Tests
wc.DownloadProgressChanged += (s, e) => downloadProgressInvoked.TrySetResult(true);
Task<byte[]> download = DownloadDataAsync(wc, url.ToString());
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: {ExpectedText.Length}\r\n" +
"\r\n" +
$"{ExpectedText}");
await server.AcceptConnectionSendResponseAndCloseAsync(content: ExpectedText);
Assert.Equal(ExpectedText, Encoding.ASCII.GetString(await download));
Assert.True(!IsAsync || await downloadProgressInvoked.Task, "Expected download progress callback to be invoked");
if (IsAsync)
{
await downloadProgressInvoked.Task.TimeoutAfter(TimeoutMilliseconds);
}
});
}
@ -559,15 +546,24 @@ namespace System.Net.Tests
{
string largeText = GetRandomText(1024 * 1024);
var downloadProgressInvokedWithContentLength = new TaskCompletionSource<bool>();
var wc = new WebClient();
wc.DownloadProgressChanged += (s, e) =>
{
if (e.TotalBytesToReceive == largeText.Length && e.BytesReceived < e.TotalBytesToReceive)
{
downloadProgressInvokedWithContentLength.TrySetResult(true);
}
};
Task<byte[]> download = DownloadDataAsync(wc, url.ToString());
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: {largeText.Length}\r\n" +
"\r\n" +
$"{largeText}");
await server.AcceptConnectionSendResponseAndCloseAsync(content: largeText);
Assert.Equal(largeText, Encoding.ASCII.GetString(await download));
if (IsAsync)
{
await downloadProgressInvokedWithContentLength.Task.TimeoutAfter(TimeoutMilliseconds);
}
});
}
@ -581,12 +577,7 @@ namespace System.Net.Tests
{
var wc = new WebClient();
Task download = DownloadFileAsync(wc, url.ToString(), tempPath);
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: {ExpectedText.Length}\r\n" +
"\r\n" +
$"{ExpectedText}");
await server.AcceptConnectionSendResponseAndCloseAsync(content: ExpectedText);
await download;
Assert.Equal(ExpectedText, File.ReadAllText(tempPath));
@ -605,12 +596,7 @@ namespace System.Net.Tests
{
var wc = new WebClient();
Task<Stream> download = OpenReadAsync(wc, url.ToString());
await LoopbackServer.ReadRequestAndSendResponseAsync(server,
"HTTP/1.1 200 OK\r\n" +
$"Date: {DateTimeOffset.UtcNow:R}\r\n" +
$"Content-Length: {ExpectedText.Length}\r\n" +
"\r\n" +
$"{ExpectedText}");
await server.AcceptConnectionSendResponseAndCloseAsync(content: ExpectedText);
using (var reader = new StreamReader(await download))
{
@ -644,7 +630,10 @@ namespace System.Net.Tests
byte[] result = await UploadDataAsync(wc, echoServer.ToString(), Encoding.UTF8.GetBytes(ExpectedText));
Assert.Contains(ExpectedText, Encoding.UTF8.GetString(result));
Assert.True(!IsAsync || await uploadProgressInvoked.Task, "Expected upload progress callback to be invoked");
if(IsAsync)
{
await uploadProgressInvoked.Task.TimeoutAfter(TimeoutMilliseconds);
}
}
[OuterLoop("Networking test talking to remote server: issue #11345")]