[System] Fix tests that regressed in e6536dd.
authorRolf Bjarne Kvinge <rolf@xamarin.com>
Thu, 29 Sep 2016 10:01:49 +0000 (12:01 +0200)
committerRolf Bjarne Kvinge <rolf@xamarin.com>
Thu, 29 Sep 2016 10:01:49 +0000 (12:01 +0200)
* I got confused between [TestFixtureSetup] and [Setup], so fix tests whose
  [Setup] methods were changed/removed to properly clean up after each test
  (using a [TearDown] method) so that the next time the on-demand creation of
  objects works as expected (i.e. objects created in the [Setup] method should
  be created on-demand once for each method instead of once for each class).

* Also fix SocketAcceptAsyncTest, the change to properly catch exceptions on
  background threads was incorrect.

mcs/class/System/Test/System.Net.Mail/SmtpClientTest.cs
mcs/class/System/Test/System.Net.Sockets/SocketAcceptAsyncTest.cs
mcs/class/System/Test/System.Net/HttpListenerTest.cs

index 8c163f77b02be58b6b816e1d50f28c4b23b4eee6..d3a39e413151fd52b8ed138b38e504c54e79c758 100644 (file)
@@ -34,6 +34,7 @@ namespace MonoTests.System.Net.Mail
                [TearDown]
                public void TearDown ()
                {
+                       _smtp = null;
                        if (Directory.Exists (tempFolder))
                                Directory.Delete (tempFolder, true);
                }
index d09341b9710d9d781ea7e4852ccdd15303c06bdf..fff160c768c6e5dac98c6c2986e6c83140d74d95 100644 (file)
@@ -48,10 +48,9 @@ namespace MonoTests.System.Net.Sockets
                                        if (listenSocket.AcceptAsync(asyncEventArgs))
                                                return;
                                        acceptedSocket = asyncEventArgs.AcceptSocket;
+                                       mainEvent.Set();
                                } catch (Exception e) {
                                        ex = e;
-                               } finally {
-                                       mainEvent.Set();
                                }
                        });
                        Assert.IsTrue(readyEvent.WaitOne(1500));
@@ -64,7 +63,7 @@ namespace MonoTests.System.Net.Sockets
                        clientSocket.NoDelay = true;
 
                        Assert.IsTrue(mainEvent.WaitOne(1500));
-                       Assert.AreEqual(serverSocket, acceptedSocket);
+                       Assert.AreEqual(serverSocket, acceptedSocket, "x");
                        mainEvent.Reset();
 
                        if (acceptedSocket != null)
index bbd716c0ed267f6c00aeb6956e16cbc354b1bb51..09d3cb0f3f291b649f7d12290719817cc4d51028 100644 (file)
@@ -44,6 +44,12 @@ namespace MonoTests.System.Net {
                        get { return _port ?? (_port = NetworkHelpers.FindFreePort ()).Value; }
                }
 
+               [TearDown]
+               public void Teardown ()
+               {
+                       _port = null;
+               }
+
                [Test]
 #if FEATURE_NO_BSD_SOCKETS
                [ExpectedException (typeof (PlatformNotSupportedException))]