Selaa lähdekoodia

Merge branch 'develop' of tig:gui-cs/Terminal.Gui into develop

Charlie Kindel 2 vuotta sitten
vanhempi
commit
b7ecb827f0
3 muutettua tiedostoa jossa 17 lisäystä ja 12 poistoa
  1. 2 5
      Terminal.Gui/Core/Application.cs
  2. 2 2
      UnitTests/ApplicationTests.cs
  3. 13 5
      UnitTests/MainLoopTests.cs

+ 2 - 5
Terminal.Gui/Core/Application.cs

@@ -656,11 +656,8 @@ namespace Terminal.Gui {
 					lastMouseOwnerView?.OnMouseLeave (me);
 				}
 				// System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
-				if (mouseGrabView != null) {
-					mouseGrabView.OnMouseEvent (nme);
-					if (mouseGrabView != null) {
-						return;
-					}
+				if (mouseGrabView != null && mouseGrabView.OnMouseEvent (nme)) {
+					return;
 				}
 			}
 

+ 2 - 2
UnitTests/ApplicationTests.cs

@@ -1301,7 +1301,7 @@ namespace Terminal.Gui.Core {
 					var myi = i;
 
 					Task.Run (() => {
-						Task.Delay (100).Wait ();
+						Thread.Sleep (100);
 
 						// each thread registers lots of 1s timeouts
 						for (int j = 0; j < numberOfTimeoutsPerThread; j++) {
@@ -1318,7 +1318,7 @@ namespace Terminal.Gui.Core {
 						if (myi == 0) {
 
 							// let the timeouts run for a bit
-							Task.Delay (5000).Wait ();
+							Thread.Sleep (5000);
 
 							// then tell the application to quit
 							Application.MainLoop.Invoke (() => Application.RequestStop ());

+ 13 - 5
UnitTests/MainLoopTests.cs

@@ -527,14 +527,19 @@ namespace Terminal.Gui.Core {
 		// TODO: Add IMainLoop tests
 
 		volatile static int tbCounter = 0;
+		static ManualResetEventSlim _wakeUp = new ManualResetEventSlim (false);
 
-		private static void Launch (Random r, TextField tf)
+		private static void Launch (Random r, TextField tf, int target)
 		{
 			Task.Run (() => {
 				Thread.Sleep (r.Next (2, 4));
 				Application.MainLoop.Invoke (() => {
 					tf.Text = $"index{r.Next ()}";
 					Interlocked.Increment (ref tbCounter);
+					if (target == tbCounter) {
+						// On last increment wake up the check
+						_wakeUp.Set ();
+					}
 				});
 			});
 		}
@@ -542,16 +547,19 @@ namespace Terminal.Gui.Core {
 		private static void RunTest (Random r, TextField tf, int numPasses, int numIncrements, int pollMs)
 		{
 			for (int j = 0; j < numPasses; j++) {
+
+				_wakeUp.Reset ();
 				for (var i = 0; i < numIncrements; i++) {
-					Launch (r, tf);
+					Launch (r, tf, (j + 1) * numIncrements);
 				}
 
+
 				while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
 				{
 					var tbNow = tbCounter;
-					Thread.Sleep (pollMs);
+					_wakeUp.Wait (pollMs);
 					if (tbCounter == tbNow) {
-						// No change after sleep: Idle handlers added via Application.MainLoop.Invoke have gone missing
+						// No change after wait: Idle handlers added via Application.MainLoop.Invoke have gone missing
 						Application.MainLoop.Invoke (() => Application.RequestStop ());
 						throw new TimeoutException (
 							$"Timeout: Increment lost. tbCounter ({tbCounter}) didn't " +
@@ -572,7 +580,7 @@ namespace Terminal.Gui.Core {
 
 			const int numPasses = 10;
 			const int numIncrements = 10000;
-			const int pollMs = 500;
+			const int pollMs = 20000;
 
 			var task = Task.Run (() => RunTest (r, tf, numPasses, numIncrements, pollMs));