Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -837,6 +837,90 @@ namespace System.Net.Sockets.Tests
Assert.Equal(e.SocketErrorCode, SocketError.InvalidArgument);
}
}
[Fact]
public async Task SendAsync_ConcurrentDispose_SucceedsOrThrowsAppropriateException()
{
if (UsesSync) return;
for (int i = 0; i < 20; i++) // run multiple times to attempt to force various interleavings
{
(Socket client, Socket server) = CreateConnectedSocketPair();
using (client)
using (server)
using (var b = new Barrier(2))
{
Task dispose = Task.Factory.StartNew(() =>
{
b.SignalAndWait();
client.Dispose();
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
Task send = Task.Factory.StartNew(() =>
{
b.SignalAndWait();
SendAsync(client, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
await dispose;
Exception error = await Record.ExceptionAsync(() => send);
if (error != null)
{
Assert.True(error is ObjectDisposedException || error is SocketException, error.ToString());
}
}
}
}
[Fact]
public async Task ReceiveAsync_ConcurrentDispose_SucceedsOrThrowsAppropriateException()
{
if (UsesSync) return;
for (int i = 0; i < 20; i++) // run multiple times to attempt to force various interleavings
{
(Socket client, Socket server) = CreateConnectedSocketPair();
using (client)
using (server)
using (var b = new Barrier(2))
{
Task dispose = Task.Factory.StartNew(() =>
{
b.SignalAndWait();
client.Dispose();
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
Task send = Task.Factory.StartNew(() =>
{
SendAsync(server, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
b.SignalAndWait();
ReceiveAsync(client, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
await dispose;
Exception error = await Record.ExceptionAsync(() => send);
if (error != null)
{
Assert.True(error is ObjectDisposedException || error is SocketException, error.ToString());
}
}
}
}
protected static (Socket, Socket) CreateConnectedSocketPair()
{
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
listener.Listen(1);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(listener.LocalEndPoint);
Socket server = listener.Accept();
return (client, server);
}
}
}
public class SendReceive
@@ -1248,21 +1332,6 @@ namespace System.Net.Sockets.Tests
}
}).Dispose();
}
private static (Socket, Socket) CreateConnectedSocketPair()
{
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
listener.Listen(1);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(listener.LocalEndPoint);
Socket server = listener.Accept();
return (client, server);
}
}
}
public sealed class SendReceiveSyncForceNonBlocking : SendReceive<SocketHelperSyncForceNonBlocking> { }

View File

@@ -84,7 +84,7 @@ namespace System.Net.Sockets.Tests
}
[OuterLoop] // TODO: Issue #11345
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
{
// On all platforms, index 0 means "any interface"
@@ -92,7 +92,7 @@ namespace System.Net.Sockets.Tests
}
[OuterLoop] // TODO: Issue #11345
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
[PlatformSpecific(TestPlatforms.Windows)] // see comment below
[ActiveIssue(21327, TargetFrameworkMonikers.Uap)] // UWP Apps are forbidden to send network traffic to the local Computer.
public async Task MulticastInterface_Set_Loopback_Succeeds()
@@ -151,7 +151,7 @@ namespace System.Net.Sockets.Tests
}
[OuterLoop] // TODO: Issue #11345
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
{
if (PlatformDetection.IsFedora || PlatformDetection.IsRedHatFamily7 || PlatformDetection.IsOSX)
@@ -164,7 +164,7 @@ namespace System.Net.Sockets.Tests
}
[OuterLoop] // TODO: Issue #11345
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
[PlatformSpecific(TestPlatforms.Windows)]
[ActiveIssue(21327, TargetFrameworkMonikers.Uap)] // UWP Apps are forbidden to send network traffic to the local Computer.
public async void MulticastInterface_Set_IPv6_Loopback_Succeeds()