[System] Test Unhandled Ex on ConnectAsync
authorMarcos Henrich <marcos.henrich@xamarin.com>
Mon, 27 Jun 2016 08:50:48 +0000 (09:50 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Mon, 27 Jun 2016 09:42:05 +0000 (10:42 +0100)
Covers #41616

Our console runner is currently swallowing this test unhandled
exceptions.

To make it test show the failure I had to set legacyUnhandledExceptionPolicy
to 0 in mcs/class/lib/net_4_x/nunit-console.exe.config

Then running we can observe the crash by running:
make -C mcs/class/System check TESTNAME=System.Net.Sockets.SocketTest.ConnectAsyncUnhandledEx

Other tests appear to crash with legacyUEP set to 0, while the runner
shows no errors.

mcs/class/System/Test/System.Net.Sockets/SocketTest.cs

index 2b12d7019bffad7b8ebc05bd816b8e773a684871..f4586a253f8ce09c2b2178d6f5e08ad53b55445a 100755 (executable)
@@ -15,6 +15,7 @@ using System.Collections;
 using System.Threading;
 using System.Reflection;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
 using System.Net;
 using System.Net.Sockets;
 using NUnit.Framework;
@@ -4345,6 +4346,23 @@ namespace MonoTests.System.Net.Sockets
                                socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 19);
                        }
                }
+
+               [Test] // Covers 41616
+               public void ConnectAsyncUnhandledEx ()
+               {
+                       var mre = new ManualResetEvent (false);
+
+                       var endPoint = new IPEndPoint(0,0);
+                       var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified);
+
+                       var socketArgs = new SocketAsyncEventArgs();
+                       socketArgs.RemoteEndPoint = endPoint;
+                       socketArgs.Completed += (sender, e) => mre.Set ();
+
+                       socket.ConnectAsync (socketArgs);
+
+                       Assert.IsTrue (mre.WaitOne (1000), "ConnectedAsync timeout");
+               }
        }
 }