Prechádzať zdrojové kódy

[System] Test Unhandled Ex on ConnectAsync

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.
Marcos Henrich 9 rokov pred
rodič
commit
a05bc5465a

+ 18 - 0
mcs/class/System/Test/System.Net.Sockets/SocketTest.cs

@@ -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");
+		}
  	}
 }