You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
@@ -116,6 +116,110 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(5)]
|
||||
public async Task AcceptAsync_ConcurrentAcceptsBeforeConnects_Success(int numberAccepts)
|
||||
{
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
listener.Listen(numberAccepts);
|
||||
|
||||
var clients = new Socket[numberAccepts];
|
||||
var servers = new Task<Socket>[numberAccepts];
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < numberAccepts; i++)
|
||||
{
|
||||
clients[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
servers[i] = listener.AcceptAsync();
|
||||
}
|
||||
|
||||
foreach (Socket client in clients)
|
||||
{
|
||||
client.Connect(listener.LocalEndPoint);
|
||||
}
|
||||
|
||||
await Task.WhenAll(servers);
|
||||
Assert.All(servers, s => Assert.Equal(TaskStatus.RanToCompletion, s.Status));
|
||||
Assert.All(servers, s => Assert.NotNull(s.Result));
|
||||
Assert.All(servers, s => Assert.True(s.Result.Connected));
|
||||
}
|
||||
finally
|
||||
{
|
||||
foreach (Socket client in clients)
|
||||
{
|
||||
client?.Dispose();
|
||||
}
|
||||
|
||||
foreach (Task<Socket> server in servers)
|
||||
{
|
||||
if (server?.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
server.Result.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(5)]
|
||||
public async Task AcceptAsync_ConcurrentAcceptsAfterConnects_Success(int numberAccepts)
|
||||
{
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
listener.Listen(numberAccepts);
|
||||
|
||||
var clients = new Socket[numberAccepts];
|
||||
var clientConnects = new Task[numberAccepts];
|
||||
var servers = new Task<Socket>[numberAccepts];
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < numberAccepts; i++)
|
||||
{
|
||||
clients[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
clientConnects[i] = clients[i].ConnectAsync(listener.LocalEndPoint);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberAccepts; i++)
|
||||
{
|
||||
servers[i] = listener.AcceptAsync();
|
||||
}
|
||||
|
||||
await Task.WhenAll(clientConnects);
|
||||
Assert.All(clientConnects, c => Assert.Equal(TaskStatus.RanToCompletion, c.Status));
|
||||
|
||||
await Task.WhenAll(servers);
|
||||
Assert.All(servers, s => Assert.Equal(TaskStatus.RanToCompletion, s.Status));
|
||||
Assert.All(servers, s => Assert.NotNull(s.Result));
|
||||
Assert.All(servers, s => Assert.True(s.Result.Connected));
|
||||
}
|
||||
finally
|
||||
{
|
||||
foreach (Socket client in clients)
|
||||
{
|
||||
client?.Dispose();
|
||||
}
|
||||
|
||||
foreach (Task<Socket> server in servers)
|
||||
{
|
||||
if (server?.Status == TaskStatus.RanToCompletion)
|
||||
{
|
||||
server.Result.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // Unix platforms don't yet support receiving data with AcceptAsync.
|
||||
|
@@ -503,6 +503,7 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Socket.Select(null, null, largeList, -1));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in AcceptAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void AcceptAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -535,6 +536,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ReceiveAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void ConnectAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -585,6 +587,7 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<NotSupportedException>(() => GetSocket(AddressFamily.InterNetwork).ConnectAsync(eventArgs));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ConnectAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void ConnectAsync_Static_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -607,12 +610,14 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<ArgumentNullException>(() => Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, s_eventArgs));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ReceiveAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void ReceiveAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GetSocket().ReceiveAsync(null));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ReceiveFromAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void ReceiveFromAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -635,6 +640,7 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<ArgumentException>(() => GetSocket(AddressFamily.InterNetwork).ReceiveFromAsync(eventArgs));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ReceiveMessageFromAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void ReceiveMessageFromAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -657,18 +663,21 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<ArgumentException>(() => GetSocket(AddressFamily.InterNetwork).ReceiveMessageFromAsync(eventArgs));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void SendAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GetSocket().SendAsync(null));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendPacketsAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void SendPacketsAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GetSocket().SendPacketsAsync(null));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendPacketsAsync that dereferences null SAEA.SendPacketsElements")]
|
||||
[Fact]
|
||||
public void SendPacketsAsync_NullSendPacketsElements_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -685,6 +694,7 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Throws<NotSupportedException>(() => GetSocket().SendPacketsAsync(eventArgs));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendToAsync that dereferences null SAEA argument")]
|
||||
[Fact]
|
||||
public void SendToAsync_NullAsyncEventArgs_Throws_ArgumentNull()
|
||||
{
|
||||
@@ -1122,7 +1132,7 @@ namespace System.Net.Sockets.Tests
|
||||
public void BeginSend_Buffers_NullBuffers_Throws_ArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GetSocket().BeginSend(null, SocketFlags.None, TheAsyncCallback, null));
|
||||
Assert.Throws<ArgumentNullException>(() => { GetSocket().SendAsync(null, SocketFlags.None); });
|
||||
Assert.Throws<ArgumentNullException>(() => { GetSocket().SendAsync((IList<ArraySegment<byte>>)null, SocketFlags.None); });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1229,7 +1239,7 @@ namespace System.Net.Sockets.Tests
|
||||
public void BeginReceive_Buffers_NullBuffers_Throws_ArgumentNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GetSocket().BeginReceive(null, SocketFlags.None, TheAsyncCallback, null));
|
||||
Assert.Throws<ArgumentNullException>(() => { GetSocket().ReceiveAsync(null, SocketFlags.None); });
|
||||
Assert.Throws<ArgumentNullException>(() => { GetSocket().ReceiveAsync((IList<ArraySegment<byte>>)null, SocketFlags.None); });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@@ -30,8 +30,8 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("asyncResult", () => s.EndDisconnect(null));
|
||||
Assert.Throws<ArgumentException>("asyncResult", () => s.EndDisconnect(Task.CompletedTask));
|
||||
AssertExtensions.Throws<ArgumentNullException>("asyncResult", () => s.EndDisconnect(null));
|
||||
AssertExtensions.Throws<ArgumentException>("asyncResult", () => s.EndDisconnect(Task.CompletedTask));
|
||||
s.Dispose();
|
||||
Assert.Throws<ObjectDisposedException>(() => s.Disconnect(true));
|
||||
Assert.Throws<ObjectDisposedException>(() => s.BeginDisconnect(true, null, null));
|
||||
|
@@ -10,18 +10,8 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace System.Net.Sockets.Tests
|
||||
{
|
||||
public class DnsEndPointTest
|
||||
public class DnsEndPointTest : DualModeBase
|
||||
{
|
||||
// Port 8 is unassigned as per https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
|
||||
private const int UnusedPort = 8;
|
||||
|
||||
private readonly ITestOutputHelper _log;
|
||||
|
||||
public DnsEndPointTest(ITestOutputHelper output)
|
||||
{
|
||||
_log = TestLogging.GetInstance();
|
||||
}
|
||||
|
||||
private void OnConnectAsyncCompleted(object sender, SocketAsyncEventArgs args)
|
||||
{
|
||||
ManualResetEvent complete = (ManualResetEvent)args.UserToken;
|
||||
@@ -312,12 +302,11 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[ConditionalTheory(nameof(LocalhostIsBothIPv4AndIPv6))]
|
||||
[InlineData(SocketImplementationType.APM)]
|
||||
[InlineData(SocketImplementationType.Async)]
|
||||
[Trait("IPv4", "true")]
|
||||
[Trait("IPv6", "true")]
|
||||
[ActiveIssue(4002, TestPlatforms.AnyUnix)]
|
||||
public void Socket_StaticConnectAsync_Success(SocketImplementationType type)
|
||||
{
|
||||
Assert.True(Capability.IPv4Support() && Capability.IPv6Support());
|
||||
|
@@ -1 +1 @@
|
||||
9bcf3aab3ce51fc0be42dbdaab18dd936eff7a9e
|
||||
a5661e52c3bb75899c93187c9542f6ba0e8f84aa
|
@@ -10,6 +10,7 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
public class IPPacketInformationTest
|
||||
{
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in IPPacketInformation.Equals that dereferences null address")]
|
||||
[Fact]
|
||||
public void Equals_DefaultValues_Success()
|
||||
{
|
||||
@@ -18,13 +19,14 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.False(default(IPPacketInformation) != default(IPPacketInformation));
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in IPPacketInformation.GetHashCode that dereferences null address")]
|
||||
[Fact]
|
||||
public void GetHashCode_DefaultValues_Success()
|
||||
{
|
||||
Assert.Equal(default(IPPacketInformation).GetHashCode(), default(IPPacketInformation).GetHashCode());
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void Equals_NonDefaultValue_Success()
|
||||
{
|
||||
IPPacketInformation packetInfo = GetNonDefaultIPPacketInformation();
|
||||
@@ -41,7 +43,7 @@ namespace System.Net.Sockets.Tests
|
||||
int ignored = packetInfo.Interface; // just make sure it doesn't throw, nothing else to verify
|
||||
}
|
||||
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void GetHashCode_NonDefaultValue_Succes()
|
||||
{
|
||||
IPPacketInformation packetInfo = GetNonDefaultIPPacketInformation();
|
||||
|
@@ -2,6 +2,7 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Net.Sockets.Tests
|
||||
@@ -11,12 +12,12 @@ namespace System.Net.Sockets.Tests
|
||||
[Fact]
|
||||
public void MulticastOption_Ctor_InvalidArguments_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("group", () => new MulticastOption(null));
|
||||
Assert.Throws<ArgumentNullException>("group", () => new MulticastOption(null, 0));
|
||||
Assert.Throws<ArgumentNullException>("group", () => new MulticastOption(null, null));
|
||||
Assert.Throws<ArgumentNullException>("mcint", () => new MulticastOption(IPAddress.Loopback, null));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("interfaceIndex", () => new MulticastOption(IPAddress.Loopback, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("interfaceIndex", () => new MulticastOption(IPAddress.Loopback, int.MaxValue));
|
||||
AssertExtensions.Throws<ArgumentNullException>("group", () => new MulticastOption(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("group", () => new MulticastOption(null, 0));
|
||||
AssertExtensions.Throws<ArgumentNullException>("group", () => new MulticastOption(null, null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("mcint", () => new MulticastOption(IPAddress.Loopback, null));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("interfaceIndex", () => new MulticastOption(IPAddress.Loopback, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("interfaceIndex", () => new MulticastOption(IPAddress.Loopback, int.MaxValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -41,8 +42,8 @@ namespace System.Net.Sockets.Tests
|
||||
option = new MulticastOption(IPAddress.Any, 42);
|
||||
Assert.Equal(42, option.InterfaceIndex);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = -1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = int.MaxValue);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = -1);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = int.MaxValue);
|
||||
|
||||
option.InterfaceIndex = 1;
|
||||
Assert.Equal(1, option.InterfaceIndex);
|
||||
@@ -69,10 +70,10 @@ namespace System.Net.Sockets.Tests
|
||||
[Fact]
|
||||
public void IPv6MulticastOption_Ctor_InvalidArguments_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("group", () => new IPv6MulticastOption(null));
|
||||
Assert.Throws<ArgumentNullException>("group", () => new IPv6MulticastOption(null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("ifindex", () => new IPv6MulticastOption(IPAddress.Loopback, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("ifindex", () => new IPv6MulticastOption(IPAddress.Loopback, long.MaxValue));
|
||||
AssertExtensions.Throws<ArgumentNullException>("group", () => new IPv6MulticastOption(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("group", () => new IPv6MulticastOption(null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("ifindex", () => new IPv6MulticastOption(IPAddress.Loopback, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("ifindex", () => new IPv6MulticastOption(IPAddress.Loopback, long.MaxValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +82,7 @@ namespace System.Net.Sockets.Tests
|
||||
var option = new IPv6MulticastOption(IPAddress.Any);
|
||||
Assert.Same(IPAddress.Any, option.Group);
|
||||
|
||||
Assert.Throws<ArgumentNullException>("value", () => option.Group = null);
|
||||
AssertExtensions.Throws<ArgumentNullException>("value", () => option.Group = null);
|
||||
|
||||
option.Group = IPAddress.Broadcast;
|
||||
Assert.Same(IPAddress.Broadcast, option.Group);
|
||||
@@ -96,8 +97,8 @@ namespace System.Net.Sockets.Tests
|
||||
option = new IPv6MulticastOption(IPAddress.Any, 42);
|
||||
Assert.Equal(42, option.InterfaceIndex);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = -1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = long.MaxValue);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = -1);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => option.InterfaceIndex = long.MaxValue);
|
||||
|
||||
option.InterfaceIndex = 1;
|
||||
Assert.Equal(1, option.InterfaceIndex);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
@@ -14,11 +15,11 @@ namespace System.Net.Sockets.Tests
|
||||
[Fact]
|
||||
public void Ctor_NullSocket_ThrowsArgumentNullExceptions()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("socket", () => new NetworkStream(null));
|
||||
Assert.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, false));
|
||||
Assert.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, true));
|
||||
Assert.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, FileAccess.ReadWrite));
|
||||
Assert.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, FileAccess.ReadWrite, false));
|
||||
AssertExtensions.Throws<ArgumentNullException>("socket", () => new NetworkStream(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, false));
|
||||
AssertExtensions.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, true));
|
||||
AssertExtensions.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, FileAccess.ReadWrite));
|
||||
AssertExtensions.Throws<ArgumentNullException>("socket", () => new NetworkStream(null, FileAccess.ReadWrite, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -581,8 +582,8 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
await RunWithConnectedNetworkStreamsAsync((server, client) =>
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => server.ReadTimeout = invalidTimeout);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => server.WriteTimeout = invalidTimeout);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => server.ReadTimeout = invalidTimeout);
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => server.WriteTimeout = invalidTimeout);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
@@ -645,11 +646,11 @@ namespace System.Net.Sockets.Tests
|
||||
await RunWithConnectedNetworkStreamsAsync((stream, _) =>
|
||||
{
|
||||
// Null destination
|
||||
Assert.Throws<ArgumentNullException>("destination", () => { stream.CopyToAsync(null); });
|
||||
AssertExtensions.Throws<ArgumentNullException>("destination", () => { stream.CopyToAsync(null); });
|
||||
|
||||
// Buffer size out-of-range
|
||||
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), 0); });
|
||||
Assert.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), 0); });
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("bufferSize", () => { stream.CopyToAsync(new MemoryStream(), -1, CancellationToken.None); });
|
||||
|
||||
// Copying to non-writable stream
|
||||
Assert.Throws<NotSupportedException>(() => { stream.CopyToAsync(new MemoryStream(new byte[0], writable: false)); });
|
||||
@@ -669,20 +670,34 @@ namespace System.Net.Sockets.Tests
|
||||
});
|
||||
}
|
||||
|
||||
[ActiveIssue(16611, TestPlatforms.AnyUnix)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Optimized .NET Core CopyToAsync doesn't use Begin/EndRead, skipping code that throws ObjectDisposedException on netfx")]
|
||||
[Fact]
|
||||
public async Task CopyToAsync_DisposedSourceStream_Throws()
|
||||
public async Task CopyToAsync_DisposedSourceStream_ThrowsOnWindows_NoThrowOnUnix()
|
||||
{
|
||||
await RunWithConnectedNetworkStreamsAsync(async (stream, _) =>
|
||||
{
|
||||
// Copying while and then after disposing the stream
|
||||
// Copying while disposing the stream
|
||||
Task copyTask = stream.CopyToAsync(new MemoryStream());
|
||||
stream.Dispose();
|
||||
await Assert.ThrowsAsync<IOException>(() => copyTask);
|
||||
Exception e = await Record.ExceptionAsync(() => copyTask);
|
||||
|
||||
// Difference in shutdown/close behavior between Windows and Unix.
|
||||
// On Windows, the outstanding receive is completed as aborted when the
|
||||
// socket is closed. On Unix, it's completed as successful once or after
|
||||
// the shutdown is issued, but depending on timing, if it's then closed
|
||||
// before that takes effect, it may also complete as aborted.
|
||||
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
Assert.True(
|
||||
(isWindows && e is IOException) ||
|
||||
(!isWindows && (e == null || e is IOException)),
|
||||
$"Got unexpected exception: {e?.ToString() ?? "(null)"}");
|
||||
|
||||
// Copying after disposing the stream
|
||||
Assert.Throws<ObjectDisposedException>(() => { stream.CopyToAsync(new MemoryStream()); });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task CopyToAsync_NonReadableSourceStream_Throws()
|
||||
{
|
||||
|
@@ -17,6 +17,7 @@ namespace System.Net.Sockets.Tests
|
||||
#pragma warning restore
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "SupportsIPv6 factors in config data")]
|
||||
[Fact]
|
||||
public void SupportsIPv6_MatchesOSSupportsIPv6()
|
||||
{
|
||||
|
@@ -11,7 +11,7 @@ namespace System.Net.Sockets.Tests
|
||||
public class ReceiveMessageFrom
|
||||
{
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void Success()
|
||||
{
|
||||
if (Socket.OSSupportsIPv4)
|
||||
@@ -45,7 +45,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void Success_IPv6()
|
||||
{
|
||||
if (Socket.OSSupportsIPv6)
|
||||
@@ -79,7 +79,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void Success_APM(bool ipv4)
|
||||
@@ -130,7 +130,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Theory]
|
||||
[InlineData(false, 0)]
|
||||
[InlineData(false, 1)]
|
||||
[InlineData(false, 2)]
|
||||
|
@@ -17,7 +17,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void Success_IPv4()
|
||||
{
|
||||
ManualResetEvent completed = new ManualResetEvent(false);
|
||||
@@ -61,7 +61,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Fact]
|
||||
public void Success_IPv6()
|
||||
{
|
||||
ManualResetEvent completed = new ManualResetEvent(false);
|
||||
@@ -105,7 +105,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsSubsystemForLinux))] // https://github.com/Microsoft/BashOnWindows/issues/987
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task Task_Success(bool ipv4)
|
||||
|
@@ -13,17 +13,16 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
public class SendFileTest
|
||||
{
|
||||
public static IEnumerable<object[]> SendFile_MemberData_Small() => SendFile_MemberData(1024);
|
||||
|
||||
public static IEnumerable<object[]> SendFile_MemberData_Large() => SendFile_MemberData(12345678);
|
||||
|
||||
public static IEnumerable<object[]> SendFile_MemberData(int bytesToSend)
|
||||
public static IEnumerable<object[]> SendFile_MemberData()
|
||||
{
|
||||
foreach (IPAddress listenAt in new[] { IPAddress.Loopback, IPAddress.IPv6Loopback })
|
||||
{
|
||||
foreach (bool sendPreAndPostBuffers in new[] { true, false })
|
||||
{
|
||||
yield return new object[] { listenAt, sendPreAndPostBuffers, bytesToSend };
|
||||
foreach (int bytesToSend in new[] { 512, 1024, 12345678 })
|
||||
{
|
||||
yield return new object[] { listenAt, sendPreAndPostBuffers, bytesToSend };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,12 +97,10 @@ namespace System.Net.Sockets.Tests
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(SendFile_MemberData_Small))]
|
||||
[MemberData(nameof(SendFile_MemberData_Large))]
|
||||
[MemberData(nameof(SendFile_MemberData))]
|
||||
public void SendFile_Synchronous(IPAddress listenAt, bool sendPreAndPostBuffers, int bytesToSend)
|
||||
{
|
||||
const int ListenBacklog = 1;
|
||||
const int LingerTime = 10;
|
||||
const int TestTimeout = 30000;
|
||||
|
||||
// Create file to send
|
||||
@@ -154,8 +151,7 @@ namespace System.Net.Sockets.Tests
|
||||
using (client)
|
||||
{
|
||||
client.SendFile(filename, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread);
|
||||
|
||||
client.LingerState = new LingerOption(true, LingerTime);
|
||||
client.Shutdown(SocketShutdown.Send);
|
||||
}
|
||||
|
||||
Assert.True(serverThread.Join(TestTimeout), "Completed within allowed time");
|
||||
@@ -169,96 +165,61 @@ namespace System.Net.Sockets.Tests
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(SendFile_MemberData_Large))]
|
||||
[ActiveIssue(17188, TestPlatforms.OSX)] // recombine into SendFile_APM once fixed
|
||||
public void SendFile_APM_Large(IPAddress listenAt, bool sendPreAndPostBuffers, int bytesToSend) =>
|
||||
SendFile_APM(listenAt, sendPreAndPostBuffers, bytesToSend);
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(SendFile_MemberData_Small))]
|
||||
[MemberData(nameof(SendFile_MemberData))]
|
||||
public void SendFile_APM(IPAddress listenAt, bool sendPreAndPostBuffers, int bytesToSend)
|
||||
{
|
||||
const int ListenBacklog = 1;
|
||||
const int LingerTime = 10;
|
||||
const int TestTimeout = 30000;
|
||||
const int ListenBacklog = 1, TestTimeout = 30000;
|
||||
|
||||
// Create file to send
|
||||
byte[] preBuffer;
|
||||
byte[] postBuffer;
|
||||
byte[] preBuffer, postBuffer;
|
||||
Fletcher32 sentChecksum;
|
||||
string filename = CreateFileToSend(bytesToSend, sendPreAndPostBuffers, out preBuffer, out postBuffer, out sentChecksum);
|
||||
|
||||
// Start server
|
||||
var server = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
server.BindToAnonymousPort(listenAt);
|
||||
|
||||
server.Listen(ListenBacklog);
|
||||
|
||||
var serverFinished = new TaskCompletionSource<bool>();
|
||||
int bytesReceived = 0;
|
||||
var receivedChecksum = new Fletcher32();
|
||||
|
||||
server.AcceptAPM(remote =>
|
||||
using (var listener = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
Action<int> recvHandler = null;
|
||||
bool first = true;
|
||||
listener.BindToAnonymousPort(listenAt);
|
||||
listener.Listen(ListenBacklog);
|
||||
|
||||
var recvBuffer = new byte[256];
|
||||
recvHandler = received =>
|
||||
int bytesReceived = 0;
|
||||
var receivedChecksum = new Fletcher32();
|
||||
|
||||
Task serverTask = Task.Run(async () =>
|
||||
{
|
||||
if (!first)
|
||||
using (var serverStream = new NetworkStream(await listener.AcceptAsync(), ownsSocket: true))
|
||||
{
|
||||
if (received == 0)
|
||||
var buffer = new byte[256];
|
||||
int bytesRead;
|
||||
while ((bytesRead = await serverStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
remote.Dispose();
|
||||
server.Dispose();
|
||||
serverFinished.SetResult(true);
|
||||
return;
|
||||
bytesReceived += bytesRead;
|
||||
receivedChecksum.Add(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
bytesReceived += received;
|
||||
receivedChecksum.Add(recvBuffer, 0, received);
|
||||
}
|
||||
else
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
|
||||
remote.ReceiveAPM(recvBuffer, 0, recvBuffer.Length, SocketFlags.None, recvHandler);
|
||||
};
|
||||
|
||||
recvHandler(0);
|
||||
});
|
||||
|
||||
// Run client
|
||||
EndPoint clientEndpoint = server.LocalEndPoint;
|
||||
var client = new Socket(clientEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
var clientFinished = new TaskCompletionSource<bool>();
|
||||
client.ConnectAPM(clientEndpoint, () =>
|
||||
{
|
||||
client.SendFileAPM(filename, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread, ex =>
|
||||
{
|
||||
client.LingerState = new LingerOption(true, LingerTime);
|
||||
client.Dispose();
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
clientFinished.SetException(ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
clientFinished.SetResult(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
Task clientTask = Task.Run(async () =>
|
||||
{
|
||||
using (var client = new Socket(listener.LocalEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
await client.ConnectAsync(listener.LocalEndPoint);
|
||||
await Task.Factory.FromAsync(
|
||||
(callback, state) => client.BeginSendFile(filename, preBuffer, postBuffer, TransmitFileOptions.UseDefaultWorkerThread, callback, state),
|
||||
iar => client.EndSendFile(iar),
|
||||
null);
|
||||
client.Shutdown(SocketShutdown.Send);
|
||||
}
|
||||
});
|
||||
|
||||
Assert.True(clientFinished.Task.Wait(TestTimeout), "Completed within allowed time");
|
||||
Assert.True(serverFinished.Task.Wait(TestTimeout), "Completed within allowed time");
|
||||
// Wait for the tasks to complete
|
||||
Task<Task> firstCompleted = Task.WhenAny(serverTask, clientTask);
|
||||
Assert.True(firstCompleted.Wait(TestTimeout), "Neither client nor server task completed within allowed time");
|
||||
firstCompleted.Result.GetAwaiter().GetResult();
|
||||
Assert.True(Task.WaitAll(new[] { serverTask, clientTask }, TestTimeout), $"Tasks didn't complete within allowed time. Server:{serverTask.Status} Client:{clientTask.Status}");
|
||||
|
||||
Assert.Equal(bytesToSend, bytesReceived);
|
||||
Assert.Equal(sentChecksum.Sum, receivedChecksum.Sum);
|
||||
// Validate the results
|
||||
Assert.Equal(bytesToSend, bytesReceived);
|
||||
Assert.Equal(sentChecksum.Sum, receivedChecksum.Sum);
|
||||
}
|
||||
|
||||
// Clean up the file we created
|
||||
File.Delete(filename);
|
||||
|
@@ -75,6 +75,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendPacketsAsync that dereferences null SAEA argument")]
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[InlineData(SocketImplementationType.APM)]
|
||||
@@ -103,13 +104,13 @@ namespace System.Net.Sockets.Tests
|
||||
Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
|
||||
// Needs to be connected before send
|
||||
|
||||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
{
|
||||
socket.SendPacketsAsync(new SocketAsyncEventArgs());
|
||||
socket.SendPacketsAsync(new SocketAsyncEventArgs { SendPacketsElements = new SendPacketsElement[0] });
|
||||
});
|
||||
Assert.Equal("e.SendPacketsElements", ex.ParamName);
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendPacketsAsync that dereferences null m_SendPacketsElementsInternal array")]
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[InlineData(SocketImplementationType.APM)]
|
||||
|
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -32,7 +31,8 @@ namespace System.Net.Sockets.Tests
|
||||
public abstract Task<int> SendToAsync(Socket s, ArraySegment<byte> buffer, EndPoint endpoint);
|
||||
public virtual bool GuaranteedSendOrdering => true;
|
||||
public virtual bool ValidatesArrayArguments => true;
|
||||
public virtual bool SupportsNonBlocking => true;
|
||||
public virtual bool UsesSync => false;
|
||||
public virtual bool DisposeDuringOperationResultsInDisposedException => false;
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0, 0)] // null array
|
||||
@@ -61,6 +61,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ActiveIssue(16945)] // Packet loss, potentially due to other tests running at the same time
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(Loopbacks))]
|
||||
@@ -254,6 +255,57 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(Loopbacks))]
|
||||
public async Task SendRecv_Stream_TCP_LargeMultiBufferSends(IPAddress listenAt)
|
||||
{
|
||||
using (var listener = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
||||
using (var client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.BindToAnonymousPort(listenAt);
|
||||
listener.Listen(1);
|
||||
|
||||
Task<Socket> acceptTask = AcceptAsync(listener);
|
||||
await client.ConnectAsync(listener.LocalEndPoint);
|
||||
using (Socket server = await acceptTask)
|
||||
{
|
||||
var sentChecksum = new Fletcher32();
|
||||
var rand = new Random();
|
||||
int bytesToSend = 0;
|
||||
var buffers = new List<ArraySegment<byte>>();
|
||||
const int NumBuffers = 5;
|
||||
for (int i = 0; i < NumBuffers; i++)
|
||||
{
|
||||
var sendBuffer = new byte[12345678];
|
||||
rand.NextBytes(sendBuffer);
|
||||
bytesToSend += sendBuffer.Length - i; // trim off a few bytes to test offset/count
|
||||
sentChecksum.Add(sendBuffer, i, sendBuffer.Length - i);
|
||||
buffers.Add(new ArraySegment<byte>(sendBuffer, i, sendBuffer.Length - i));
|
||||
}
|
||||
|
||||
Task<int> sendTask = SendAsync(client, buffers);
|
||||
|
||||
var receivedChecksum = new Fletcher32();
|
||||
int bytesReceived = 0;
|
||||
byte[] recvBuffer = new byte[1024];
|
||||
while (bytesReceived < bytesToSend)
|
||||
{
|
||||
int received = await ReceiveAsync(server, new ArraySegment<byte>(recvBuffer));
|
||||
if (received <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bytesReceived += received;
|
||||
receivedChecksum.Add(recvBuffer, 0, received);
|
||||
}
|
||||
|
||||
Assert.Equal(bytesToSend, await sendTask);
|
||||
Assert.Equal(sentChecksum.Sum, receivedChecksum.Sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[MemberData(nameof(Loopbacks))]
|
||||
@@ -604,7 +656,6 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ActiveIssue(13778, TestPlatforms.OSX)]
|
||||
[Fact]
|
||||
public async Task SendRecv_0ByteReceive_Success()
|
||||
{
|
||||
@@ -634,9 +685,13 @@ namespace System.Net.Sockets.Tests
|
||||
|
||||
// The client should now wake up, getting 0 bytes with 1 byte available.
|
||||
Assert.Equal(0, await receive);
|
||||
Assert.Equal(1, client.Available); // Due to #13778, this sometimes fails on macOS
|
||||
Assert.Equal(1, client.Available);
|
||||
|
||||
// Receive that byte
|
||||
// We should be able to do another 0-byte receive that completes immediateliy
|
||||
Assert.Equal(0, await ReceiveAsync(client, new ArraySegment<byte>(new byte[1], 0, 0)));
|
||||
Assert.Equal(1, client.Available);
|
||||
|
||||
// Then receive the byte
|
||||
Assert.Equal(1, await ReceiveAsync(client, new ArraySegment<byte>(new byte[1])));
|
||||
Assert.Equal(0, client.Available);
|
||||
}
|
||||
@@ -649,7 +704,7 @@ namespace System.Net.Sockets.Tests
|
||||
[InlineData(true, 1)]
|
||||
public async Task SendRecv_BlockingNonBlocking_LingerTimeout_Success(bool blocking, int lingerTimeout)
|
||||
{
|
||||
if (!SupportsNonBlocking) return;
|
||||
if (UsesSync) return;
|
||||
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
@@ -680,11 +735,11 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ActiveIssue(16716, TestPlatforms.OSX)] // SendBufferSize = 0 throws
|
||||
[Fact]
|
||||
[PlatformSpecific(~TestPlatforms.OSX)] // SendBufferSize, ReceiveBufferSize = 0 not supported on OSX.
|
||||
public async Task SendRecv_NoBuffering_Success()
|
||||
{
|
||||
if (!SupportsNonBlocking) return;
|
||||
if (UsesSync) return;
|
||||
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
@@ -702,9 +757,8 @@ namespace System.Net.Sockets.Tests
|
||||
client.SendBufferSize = 0;
|
||||
server.ReceiveBufferSize = 0;
|
||||
|
||||
var sendBuffer = new byte[5000000];
|
||||
var sendBuffer = new byte[10000];
|
||||
Task sendTask = SendAsync(client, new ArraySegment<byte>(sendBuffer));
|
||||
Assert.False(sendTask.IsCompleted);
|
||||
|
||||
int totalReceived = 0;
|
||||
var receiveBuffer = new ArraySegment<byte>(new byte[4096]);
|
||||
@@ -719,6 +773,60 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
public async Task SendRecv_DisposeDuringPendingReceive_ThrowsSocketException()
|
||||
{
|
||||
if (UsesSync) return; // if sync, can't guarantee call will have been initiated by time of disposal
|
||||
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
listener.Listen(1);
|
||||
|
||||
Task<Socket> acceptTask = AcceptAsync(listener);
|
||||
await Task.WhenAll(
|
||||
acceptTask,
|
||||
ConnectAsync(client, new IPEndPoint(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndPoint).Port)));
|
||||
|
||||
using (Socket server = await acceptTask)
|
||||
{
|
||||
Task receiveTask = ReceiveAsync(client, new ArraySegment<byte>(new byte[1]));
|
||||
Assert.False(receiveTask.IsCompleted, "Receive should be pending");
|
||||
|
||||
client.Dispose();
|
||||
|
||||
if (DisposeDuringOperationResultsInDisposedException)
|
||||
{
|
||||
await Assert.ThrowsAsync<ObjectDisposedException>(() => receiveTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
var se = await Assert.ThrowsAsync<SocketException>(() => receiveTask);
|
||||
Assert.True(
|
||||
se.SocketErrorCode == SocketError.OperationAborted || se.SocketErrorCode == SocketError.ConnectionAborted,
|
||||
$"Expected {nameof(SocketError.OperationAborted)} or {nameof(SocketError.ConnectionAborted)}, got {se.SocketErrorCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.OSX)]
|
||||
public void SocketSendReceiveBufferSize_SetZero_ThrowsSocketException()
|
||||
{
|
||||
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
SocketException e;
|
||||
e = Assert.Throws<SocketException>(() => socket.SendBufferSize = 0);
|
||||
Assert.Equal(e.SocketErrorCode, SocketError.InvalidArgument);
|
||||
|
||||
e = Assert.Throws<SocketException>(() => socket.ReceiveBufferSize = 0);
|
||||
Assert.Equal(e.SocketErrorCode, SocketError.InvalidArgument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SendReceiveUdpClient : MemberDatas
|
||||
@@ -906,12 +1014,13 @@ namespace System.Net.Sockets.Tests
|
||||
Task.Run(() => s.SendTo(buffer.Array, buffer.Offset, buffer.Count, SocketFlags.None, endPoint));
|
||||
|
||||
public override bool GuaranteedSendOrdering => false;
|
||||
public override bool SupportsNonBlocking => false;
|
||||
public override bool UsesSync => true;
|
||||
}
|
||||
|
||||
public sealed class SendReceiveApm : SendReceive
|
||||
{
|
||||
public SendReceiveApm(ITestOutputHelper output) : base(output) { }
|
||||
public override bool DisposeDuringOperationResultsInDisposedException => true;
|
||||
public override Task<Socket> AcceptAsync(Socket s) =>
|
||||
Task.Factory.FromAsync(s.BeginAccept, s.EndAccept, null);
|
||||
public override Task ConnectAsync(Socket s, EndPoint endPoint) =>
|
||||
@@ -955,6 +1064,8 @@ namespace System.Net.Sockets.Tests
|
||||
public sealed class SendReceiveTask : SendReceive
|
||||
{
|
||||
public SendReceiveTask(ITestOutputHelper output) : base(output) { }
|
||||
public override bool DisposeDuringOperationResultsInDisposedException =>
|
||||
PlatformDetection.IsFullFramework; // due to SocketTaskExtensions.netfx implementation wrapping APM rather than EAP
|
||||
public override Task<Socket> AcceptAsync(Socket s) =>
|
||||
s.AcceptAsync();
|
||||
public override Task ConnectAsync(Socket s, EndPoint endPoint) =>
|
||||
|
@@ -1,47 +0,0 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
|
||||
namespace System.Net.Sockets.Tests
|
||||
{
|
||||
internal static partial class SocketAsyncExtensions
|
||||
{
|
||||
public static void AcceptAPM(this Socket socket, Action<Socket> handler)
|
||||
{
|
||||
var callback = new AsyncCallback(asyncResult => handler(((Socket)asyncResult.AsyncState).EndAccept(asyncResult)));
|
||||
socket.BeginAccept(callback, socket);
|
||||
}
|
||||
|
||||
public static void ConnectAPM(this Socket socket, EndPoint remoteEndpoint, Action handler)
|
||||
{
|
||||
var callback = new AsyncCallback(asyncResult =>
|
||||
{
|
||||
((Socket)asyncResult.AsyncState).EndConnect(asyncResult);
|
||||
handler();
|
||||
});
|
||||
socket.BeginConnect(remoteEndpoint, callback, socket);
|
||||
}
|
||||
|
||||
public static void ReceiveAPM(this Socket socket, byte[] buffer, int offset, int count, SocketFlags flags, Action<int> handler)
|
||||
{
|
||||
var callback = new AsyncCallback(asyncResult => handler(((Socket)asyncResult.AsyncState).EndReceive(asyncResult)));
|
||||
socket.BeginReceive(buffer, offset, count, flags, callback, socket);
|
||||
}
|
||||
|
||||
public static void SendFileAPM(this Socket socket, string filename, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, Action<Exception> handler)
|
||||
{
|
||||
var callback = new AsyncCallback(asyncResult =>
|
||||
{
|
||||
Exception exc = null;
|
||||
try
|
||||
{
|
||||
((Socket)asyncResult.AsyncState).EndSendFile(asyncResult);
|
||||
}
|
||||
catch (Exception e) { exc = e; }
|
||||
handler(exc);
|
||||
});
|
||||
socket.BeginSendFile(filename, preBuffer, postBuffer, flags, callback, socket);
|
||||
}
|
||||
}
|
||||
}
|
@@ -148,11 +148,11 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
using (var saea = new SocketAsyncEventArgs())
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>("offset", () => saea.SetBuffer(new byte[1], -1, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("offset", () => saea.SetBuffer(new byte[1], 2, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 0, -1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 0, 2));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 1, 2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("offset", () => saea.SetBuffer(new byte[1], -1, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("offset", () => saea.SetBuffer(new byte[1], 2, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 0, -1));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 0, 2));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("count", () => saea.SetBuffer(new byte[1], 1, 2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,6 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[ActiveIssue(16765)]
|
||||
[Fact]
|
||||
public void CancelConnectAsync_InstanceConnect_CancelsInProgressConnect()
|
||||
{
|
||||
@@ -287,20 +286,22 @@ namespace System.Net.Sockets.Tests
|
||||
listen.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
using (var connectSaea = new SocketAsyncEventArgs())
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
connectSaea.Completed += delegate { tcs.SetResult(true); };
|
||||
var tcs = new TaskCompletionSource<SocketError>();
|
||||
connectSaea.Completed += (s, e) => tcs.SetResult(e.SocketError);
|
||||
connectSaea.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, ((IPEndPoint)listen.LocalEndPoint).Port);
|
||||
|
||||
Assert.True(client.ConnectAsync(connectSaea));
|
||||
Assert.False(tcs.Task.IsCompleted);
|
||||
Assert.True(client.ConnectAsync(connectSaea), $"ConnectAsync completed synchronously with SocketError == {connectSaea.SocketError}");
|
||||
if (tcs.Task.IsCompleted)
|
||||
{
|
||||
Assert.NotEqual(SocketError.Success, tcs.Task.Result);
|
||||
}
|
||||
|
||||
Socket.CancelConnectAsync(connectSaea);
|
||||
Assert.False(client.Connected);
|
||||
Assert.False(client.Connected, "Expected Connected to be false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ActiveIssue(16765)]
|
||||
[Fact]
|
||||
public void CancelConnectAsync_StaticConnect_CancelsInProgressConnect()
|
||||
{
|
||||
@@ -309,12 +310,15 @@ namespace System.Net.Sockets.Tests
|
||||
listen.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
using (var connectSaea = new SocketAsyncEventArgs())
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
connectSaea.Completed += delegate { tcs.SetResult(true); };
|
||||
var tcs = new TaskCompletionSource<SocketError>();
|
||||
connectSaea.Completed += (s, e) => tcs.SetResult(e.SocketError);
|
||||
connectSaea.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, ((IPEndPoint)listen.LocalEndPoint).Port);
|
||||
|
||||
Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, connectSaea));
|
||||
Assert.False(tcs.Task.IsCompleted);
|
||||
Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, connectSaea), $"ConnectAsync completed synchronously with SocketError == {connectSaea.SocketError}");
|
||||
if (tcs.Task.IsCompleted)
|
||||
{
|
||||
Assert.NotEqual(SocketError.Success, tcs.Task.Result);
|
||||
}
|
||||
|
||||
Socket.CancelConnectAsync(connectSaea);
|
||||
}
|
||||
|
@@ -317,7 +317,7 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
using (var socket = new Socket(family, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
Assert.Throws<ArgumentException>("level", () => socket.SetIPProtectionLevel(IPProtectionLevel.Unspecified));
|
||||
AssertExtensions.Throws<ArgumentException>("level", () => socket.SetIPProtectionLevel(IPProtectionLevel.Unspecified));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{8CBA022C-635F-4C8D-9D29-CD8AAC68C8E6}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<!-- Help VS understand available configurations -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
|
||||
<ItemGroup>
|
||||
@@ -38,7 +37,6 @@
|
||||
<Compile Include="TimeoutTest.cs" />
|
||||
<Compile Include="TcpClientTest.cs" />
|
||||
<Compile Include="Shutdown.cs" />
|
||||
<Compile Include="SocketAPMExtensions.cs" />
|
||||
<Compile Include="SocketAsyncEventArgsTest.cs" />
|
||||
<Compile Include="SocketOptionNameTest.cs" />
|
||||
<Compile Include="MulticastOptionTest.cs" />
|
||||
@@ -73,6 +71,9 @@
|
||||
<Link>SocketCommon\SocketImplementationType.cs</Link>
|
||||
</Compile>
|
||||
<!-- Common test files -->
|
||||
<Compile Include="$(CommonTestPath)\System\AssertExtensions.cs">
|
||||
<Link>Common\System\AssertExtensions.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
|
||||
<Link>Common\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
|
@@ -34,9 +34,9 @@ namespace System.Net.Sockets.Tests
|
||||
[Fact]
|
||||
public void Ctor_InvalidArguments_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("localEP", () => new TcpClient(null));
|
||||
Assert.Throws<ArgumentNullException>("hostname", () => new TcpClient(null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => new TcpClient("localhost", -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("localEP", () => new TcpClient(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("hostname", () => new TcpClient(null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => new TcpClient("localhost", -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -44,13 +44,13 @@ namespace System.Net.Sockets.Tests
|
||||
{
|
||||
using (var client = new TcpClient())
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("hostname", () => client.Connect((string)null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => client.Connect("localhost", -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("hostname", () => client.Connect((string)null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => client.Connect("localhost", -1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("address", () => client.Connect((IPAddress)null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => client.Connect(IPAddress.Loopback, -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("address", () => client.Connect((IPAddress)null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => client.Connect(IPAddress.Loopback, -1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>("remoteEP", () => client.Connect(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("remoteEP", () => client.Connect(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in Connected that dereferences null Client socket")]
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
public void ConnectedAvailable_NullClient()
|
||||
@@ -247,6 +248,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ExclusiveAddressUse that dereferences null Client socket")]
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
public void ExclusiveAddressUse_NullClient()
|
||||
@@ -405,6 +407,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}
|
||||
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in TcpClient.Dispose/EndConnect: the former nulls out Client, which the latter tries to use")]
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
|
@@ -14,13 +14,13 @@ namespace System.Net.Sockets.Tests
|
||||
[Fact]
|
||||
public void Ctor_InvalidArguments_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>("localEP", () => new TcpListener(null));
|
||||
Assert.Throws<ArgumentNullException>("localaddr", () => new TcpListener(null, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => new TcpListener(IPAddress.Loopback, -1));
|
||||
AssertExtensions.Throws<ArgumentNullException>("localEP", () => new TcpListener(null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("localaddr", () => new TcpListener(null, 0));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => new TcpListener(IPAddress.Loopback, -1));
|
||||
#pragma warning disable 0618 // ctor is obsolete
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => new TcpListener(66000));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => new TcpListener(66000));
|
||||
#pragma warning restore 0618
|
||||
Assert.Throws<ArgumentOutOfRangeException>("port", () => TcpListener.Create(66000));
|
||||
AssertExtensions.Throws<ArgumentOutOfRangeException>("port", () => TcpListener.Create(66000));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user