[System*] Add category for tests that use API that require BSD sockets.
[mono.git] / mcs / class / System / Test / System.Net.Sockets / UdpClientTest.cs
index c91939192234478aca44e95dca7340697a387eba..66b15308d1f84cb08efaae91d0bbe5b8e3acc62d 100644 (file)
@@ -9,14 +9,13 @@ using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+using System.Threading.Tasks;
 
 using NUnit.Framework;
 
 namespace MonoTests.System.Net.Sockets {
-#if TARGET_JVM
-       [Ignore("UdpClient is not supported - since UDP sockets are not supported")]
-#endif
        [TestFixture]
+       [Category ("RequiresBSDSockets")]
        public class UdpClientTest {
                [Test] // .ctor ()
                public void Constructor1 ()
@@ -29,21 +28,17 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.IsNotNull (s, "Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "Client:SocketType");
                        Assert.IsFalse (client.Active, "Active");
-#if NET_2_0
                        Assert.IsFalse (client.DontFragment, "DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "Ttl");
-#endif
                        client.Close ();
                }
 
@@ -58,42 +53,37 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.IsNotNull (s, "#A:Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "#A:Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "#A:Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                        Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                        //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
+
+                       if (!Socket.OSSupportsIPv6)
+                               Assert.Ignore ("IPv6 not enabled.");
 
                        client = new MyUdpClient (AddressFamily.InterNetworkV6);
                        s = client.Client;
                        Assert.IsNotNull (s, "#B:Client");
                        Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "#B:Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "#B:Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                        Assert.IsFalse (client.Active, "#B:Active");
-#if NET_2_0
                        //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                        client.Close ();
                }
 
@@ -106,15 +96,10 @@ namespace MonoTests.System.Net.Sockets {
                        } catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.AreEqual ("family", ex.ParamName, "#A5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#A4");
-                               Assert.IsNull (ex.ParamName, "#A5");
-#endif
                        }
 
                        try {
@@ -123,13 +108,8 @@ namespace MonoTests.System.Net.Sockets {
                        } catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
-#if NET_2_0
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.AreEqual ("family", ex.ParamName, "#B5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#B4");
-                               Assert.IsNull (ex.ParamName, "#B5");
-#endif
                        }
                }
 
@@ -145,19 +125,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-       #if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-       #endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-       #if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-       #endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
@@ -169,19 +145,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#B:Client:Connected");
-       #if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-       #endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsFalse (client.Active, "#B:Active");
-       #if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-       #endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -230,19 +202,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.IsFalse (object.ReferenceEquals (clientEP, localEP), "#A:Client:LocalEndPoint/ReferenceEquality");
@@ -278,44 +246,39 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                                //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
                                Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
                        }
 
+                       if (!Socket.OSSupportsIPv6)
+                               Assert.Ignore ("IPv6 not enabled.");
+
                        using (MyUdpClient client = new MyUdpClient (IPEndPoint.MaxPort, AddressFamily.InterNetworkV6))
                        {
                                s = client.Client;
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsFalse (client.Active, "#B:Active");
-#if NET_2_0
                                //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.IPv6Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -334,15 +297,10 @@ namespace MonoTests.System.Net.Sockets {
                                // family
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.AreEqual ("family", ex.ParamName, "#A5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#A4");
-                               Assert.IsNull (ex.ParamName, "#A5");
-#endif
                        }
 
                        try {
@@ -352,15 +310,10 @@ namespace MonoTests.System.Net.Sockets {
                                // family
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.AreEqual ("family", ex.ParamName, "#B5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#B4");
-                               Assert.IsNull (ex.ParamName, "#B5");
-#endif
                        }
                }
 
@@ -404,19 +357,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsTrue (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsTrue (client.Active, "#A:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                //Assert.IsFalse (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#A:Client:LocalEndPoint/Address");
@@ -428,19 +377,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsTrue (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsTrue (client.Active, "#B:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                //Assert.IsFalse (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -514,11 +459,7 @@ namespace MonoTests.System.Net.Sockets {
                [Test] // JoinMulticastGroup (IPAddress)
                public void JoinMulticastGroup1_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -535,20 +476,12 @@ namespace MonoTests.System.Net.Sockets {
                                try {
                                        client.JoinMulticastGroup ((IPAddress) null);
                                        Assert.Fail ("#1");
-#if NET_2_0
                                } catch (ArgumentNullException ex) {
                                        Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                        Assert.IsNull (ex.InnerException, "#3");
                                        Assert.IsNotNull (ex.Message, "#4");
                                        Assert.AreEqual ("multicastAddr", ex.ParamName, "#5");
                                }
-#else
-                               } catch (NullReferenceException ex) {
-                                       Assert.AreEqual (typeof (NullReferenceException), ex.GetType (), "#2");
-                                       Assert.IsNull (ex.InnerException, "#3");
-                                       Assert.IsNotNull (ex.Message, "#4");
-                               }
-#endif
                        }
                }
 
@@ -588,9 +521,7 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
@@ -613,9 +544,7 @@ namespace MonoTests.System.Net.Sockets {
                                        Assert.IsNull (ex.InnerException, "#4");
                                        Assert.IsNotNull (ex.Message, "#5");
                                        Assert.AreEqual (10045, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                        Assert.AreEqual (SocketError.OperationNotSupported, ex.SocketErrorCode, "#7");
-#endif
                                }
                        }
                }
@@ -623,11 +552,7 @@ namespace MonoTests.System.Net.Sockets {
                [Test] // JoinMulticastGroup (In32, IPAddress)
                public void JoinMulticastGroup2_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -656,6 +581,9 @@ namespace MonoTests.System.Net.Sockets {
                [Test] // JoinMulticastGroup (Int32, IPAddress)
                public void JoinMulticastGroup2_Socket_Closed ()
                {
+                       if (!Socket.OSSupportsIPv6)
+                               Assert.Ignore ("IPv6 not enabled.");
+
                        IPAddress mcast_addr = null;
 
                        UdpClient client = new UdpClient (new IPEndPoint (IPAddress.IPv6Any, 1234));
@@ -689,9 +617,7 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
@@ -714,11 +640,7 @@ namespace MonoTests.System.Net.Sockets {
                [Test] // JoinMulticastGroup (IPAddress, Int32)
                public void JoinMulticastGroup3_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -784,15 +706,12 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
                }
 
-#if NET_2_0
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
                public void JoinMulticastGroup4_IPv4 ()
                {
@@ -913,31 +832,37 @@ namespace MonoTests.System.Net.Sockets {
                {
                        UdpClient client = null;
                        var rnd = new Random ();
-                       for (int i = 0; i < 5; i++) {
+                       for (int i = 0, max = 5; i < max; i++) {
                                int port = rnd.Next (1025, 65534);
                                try {
                                        client = new UdpClient (port);
                                        break;
-                               } catch (Exception ex) {
-                                       if (i == 5)
+                               } catch (Exception) {
+                                       if (i == max - 1)
                                                throw;
                                }
                        }
 
-                       new Thread(delegate() {
-                               Thread.Sleep(2000);
-                               client.Close();
-                               }).Start();
-
+                       ManualResetEvent ready = new ManualResetEvent (false);
                        bool got_exc = false;
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Any, 0);
-                       try {
-                               client.Receive(ref ep);
-                       } catch (SocketException) {
-                               got_exc = true;
-                       } finally {
-                               client.Close ();
-                       }
+
+                       Task receive_task = Task.Factory.StartNew (() => {
+                               IPEndPoint ep = new IPEndPoint (IPAddress.Any, 0);
+                               try {
+                                       ready.Set ();
+                                       client.Receive(ref ep);
+                               } catch (SocketException) {
+                                       got_exc = true;
+                               } finally {
+                                       client.Close ();
+                               }
+                       });
+
+                       ready.WaitOne (2000);
+                       Thread.Sleep (20);
+                       client.Close();
+
+                       Assert.IsTrue (receive_task.Wait (1000));
                        Assert.IsTrue (got_exc);
                }
 
@@ -1140,9 +1065,28 @@ namespace MonoTests.System.Net.Sockets {
 
                        client.Close ();
                }
+
+               [Test] // #6057
+               public void ReceiveIPv6 ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               Assert.Ignore ("IPv6 not enabled.");
+
+                       int PORT = 9997;
+                       using(var udpClient = new UdpClient (PORT, AddressFamily.InterNetworkV6))
+                       using(var udpClient2 = new UdpClient (PORT+1, AddressFamily.InterNetworkV6))
+                       {
+                               var dataSent = new byte [] {1,2,3};
+                               udpClient2.SendAsync (dataSent, dataSent.Length, "::1", PORT);
+
+                               IPEndPoint endPoint = new IPEndPoint (IPAddress.IPv6Any, 0);
+                               var data = udpClient.Receive (ref endPoint);
+
+                               Assert.AreEqual (dataSent.Length, data.Length);
+                       }
+               }
                
                /* No test for Ttl default as it is platform dependent */
-#endif
 
                class MyUdpClient : UdpClient
                {
@@ -1181,12 +1125,6 @@ namespace MonoTests.System.Net.Sockets {
                                set { base.Active = value; }
                        }
 
-#if ONLY_1_1
-                       public new Socket Client {
-                               get { return base.Client; }
-                               set { base.Client = value; }
-                       }
-#endif
                }
        }
 }