Skip to content

Commit b7ecb82

Browse files
committed
Merge branch 'develop' of tig:gui-cs/Terminal.Gui into develop
2 parents d9b8f5f + f57e48b commit b7ecb82

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Terminal.Gui/Core/Application.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,8 @@ static void ProcessMouseEvent (MouseEvent me)
656656
lastMouseOwnerView?.OnMouseLeave (me);
657657
}
658658
// System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
659-
if (mouseGrabView != null) {
660-
mouseGrabView.OnMouseEvent (nme);
661-
if (mouseGrabView != null) {
662-
return;
663-
}
659+
if (mouseGrabView != null && mouseGrabView.OnMouseEvent (nme)) {
660+
return;
664661
}
665662
}
666663

UnitTests/ApplicationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ public void TestAddManyTimeouts ()
13011301
var myi = i;
13021302

13031303
Task.Run (() => {
1304-
Task.Delay (100).Wait ();
1304+
Thread.Sleep (100);
13051305

13061306
// each thread registers lots of 1s timeouts
13071307
for (int j = 0; j < numberOfTimeoutsPerThread; j++) {
@@ -1318,7 +1318,7 @@ public void TestAddManyTimeouts ()
13181318
if (myi == 0) {
13191319

13201320
// let the timeouts run for a bit
1321-
Task.Delay (5000).Wait ();
1321+
Thread.Sleep (5000);
13221322

13231323
// then tell the application to quit
13241324
Application.MainLoop.Invoke (() => Application.RequestStop ());

UnitTests/MainLoopTests.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,31 +527,39 @@ public void Wakeup ()
527527
// TODO: Add IMainLoop tests
528528

529529
volatile static int tbCounter = 0;
530+
static ManualResetEventSlim _wakeUp = new ManualResetEventSlim (false);
530531

531-
private static void Launch (Random r, TextField tf)
532+
private static void Launch (Random r, TextField tf, int target)
532533
{
533534
Task.Run (() => {
534535
Thread.Sleep (r.Next (2, 4));
535536
Application.MainLoop.Invoke (() => {
536537
tf.Text = $"index{r.Next ()}";
537538
Interlocked.Increment (ref tbCounter);
539+
if (target == tbCounter) {
540+
// On last increment wake up the check
541+
_wakeUp.Set ();
542+
}
538543
});
539544
});
540545
}
541546

542547
private static void RunTest (Random r, TextField tf, int numPasses, int numIncrements, int pollMs)
543548
{
544549
for (int j = 0; j < numPasses; j++) {
550+
551+
_wakeUp.Reset ();
545552
for (var i = 0; i < numIncrements; i++) {
546-
Launch (r, tf);
553+
Launch (r, tf, (j + 1) * numIncrements);
547554
}
548555

556+
549557
while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
550558
{
551559
var tbNow = tbCounter;
552-
Thread.Sleep (pollMs);
560+
_wakeUp.Wait (pollMs);
553561
if (tbCounter == tbNow) {
554-
// No change after sleep: Idle handlers added via Application.MainLoop.Invoke have gone missing
562+
// No change after wait: Idle handlers added via Application.MainLoop.Invoke have gone missing
555563
Application.MainLoop.Invoke (() => Application.RequestStop ());
556564
throw new TimeoutException (
557565
$"Timeout: Increment lost. tbCounter ({tbCounter}) didn't " +
@@ -572,7 +580,7 @@ public async Task InvokeLeakTest ()
572580

573581
const int numPasses = 10;
574582
const int numIncrements = 10000;
575-
const int pollMs = 500;
583+
const int pollMs = 20000;
576584

577585
var task = Task.Run (() => RunTest (r, tf, numPasses, numIncrements, pollMs));
578586

0 commit comments

Comments
 (0)