[mono/monodevelop] 6fbadae8: [NUnit] Don't assume that automatic updates always work

"Alan McGovern ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141e8b28d6c-dc20cae6-ffd9-431b-8fe4-5ca29c015970-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/53a7590210b6...6fbadae887ad

   Commit: 6fbadae887ad0a62c52dd94effa285572cd219e5
   Author: Alan McGovern <[email protected]> (alanmcgovern)
     Date: 2013-10-24 04:16:33 GMT
      URL: https://github.com/mono/monodevelop/commit/6fbadae887ad0a62c52dd94effa285572cd219e5

[NUnit] Don't assume that automatic updates always work

Only guiunit can give automatic updates, regardless of whether mdtool
is used or not. As such, even if we think automatic updates might
work we should protect against the case where they do not by loading
up the xml file at the end if automatic updates have not been received.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=15477

Changed paths:
  M main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
  M main/src/addins/NUnit/Services/TcpTestListener.cs

Modified: main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
===================================================================
@@ -465,6 +465,7 @@ UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test,
 			LocalConsole cons = new LocalConsole ();
 
 			try {
+				MonoDevelop.NUnit.External.TcpTestListener tcpListener = null;
 				LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null);
 
 				if (!string.IsNullOrEmpty (cmd.Arguments))
@@ -477,20 +478,28 @@ UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test,
 				else if (!string.IsNullOrEmpty (suiteName))
 					cmd.Arguments += " -run=" + suiteName;
 				if (automaticUpdates) {
-					var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName);
+					tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName);
 					cmd.Arguments += " -port=" + tcpListener.Port;
 				}
-				var p = testContext.ExecutionContext.Execute (cmd, cons);
 
-				testContext.Monitor.CancelRequested += p.Cancel;
-				if (testContext.Monitor.IsCancelRequested)
-					p.Cancel ();
-				p.WaitForCompleted ();
-				
-				if (new FileInfo (outFile).Length == 0)
-					throw new Exception ("Command failed");
+				// Note that we always dispose the tcp listener as we don't want it listening
+				// forever if the test runner does not try to connect to it
+				using (tcpListener) {
+					var p = testContext.ExecutionContext.Execute (cmd, cons);
 
-				if (automaticUpdates) {
+					testContext.Monitor.CancelRequested += p.Cancel;
+					if (testContext.Monitor.IsCancelRequested)
+						p.Cancel ();
+					p.WaitForCompleted ();
+					
+					if (new FileInfo (outFile).Length == 0)
+						throw new Exception ("Command failed");
+				}
+
+				// mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees
+				// that if guiunit is being used then it will give us updates. If you have a regular test
+				// assembly compiled against nunit.framework.dll 
+				if (automaticUpdates && tcpListener.HasReceivedConnection) {
 					if (testName != null)
 						return localMonitor.SingleTestResult;
 					return test.GetLastResult ();

Modified: main/src/addins/NUnit/Services/TcpTestListener.cs
===================================================================
@@ -38,11 +38,15 @@
 
 namespace MonoDevelop.NUnit.External
 {
-	class TcpTestListener
+	class TcpTestListener : IDisposable
 	{
 		string testSuiteName;
 		string rootTestName;
 
+		public bool HasReceivedConnection {
+			get; private set;
+		}
+
 		List<Tuple<string,UnitTestResult>> suiteStack = new List<Tuple<string, UnitTestResult>> ();
 		IRemoteEventListener listener;
 
@@ -120,6 +124,11 @@ public TcpTestListener (IRemoteEventListener listener, string suiteName)
 			});
 		}
 
+		public void Dispose ()
+		{
+			TcpListener.Stop ();
+		}
+
 		void UpdateTestSuiteStatus (string name, bool isTest)
 		{
 			if (testSuiteName.Length > 0)


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.