Skip to content

Fixes #4172 Timeout revamp and remove continuous mouse #4173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 68 commits into from
Jul 10, 2025

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Jun 21, 2025

This is super set of #4172 and #4123 it adds also the smooth timeout class

smooth

Fixes

Proposed Changes/Todos

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

tznind and others added 30 commits June 3, 2025 19:34
…(old implementation of WantContinuousButtonPressed)
…on firing twice immediately as mouse is pressed down.
@tig
Copy link
Collaborator

tig commented Jul 7, 2025

Downloading logs, it appears the failure on macos here is inTerminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver


TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.610, 214126202166, vstest.console.dll, TestRequestSender.OnExecutionMessageReceived: Received message: {"Version":7,"MessageType":"TestExecution.StatsChange","Payload":{"NewTestResults":[{"TestCase":{"Id":"ca4b3dae-bc23-d614-8309-edaae31b00c2","FullyQualifiedName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver","DisplayName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: \"v2net\", expectedType: typeof(Terminal.Gui.Drivers.ConsoleDriverFacade<ConsoleKeyInfo>))","ExecutorUri":"executor://xunit/VsTestRunner2/netcoreapp","Source":"/Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests/bin/Debug/net8.0/UnitTests.dll","CodeFilePath":null,"LineNumber":0,"Properties":[]},"Attachments":[],"Outcome":1,"ErrorMessage":null,"ErrorStackTrace":null,"DisplayName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: \"v2net\", expectedType: typeof(Terminal.Gui.Drivers.ConsoleDriverFacade<ConsoleKeyInfo>))","Messages":[],"ComputerName":"Mac-1751908618930","Duration":"00:00:00.4498409","StartTime":"2025-07-07T17:19:33.107865+00:00","EndTime":"2025-07-07T17:19:33.107865+00:00","Properties":[]},{"TestCase":{"Id":"f5b202a3-3807-f49b-7313-2ea3c421fd98","FullyQualifiedName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver","DisplayName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: \"WindowsDriver\", expectedType: typeof(Terminal.Gui.Drivers.WindowsDriver))","ExecutorUri":"executor://xunit/VsTestRunner2/netcoreapp","Source":"/Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests/bin/Debug/net8.0/UnitTests.dll","CodeFilePath":null,"LineNumber":0,"Properties":[]},"Attachments":[],"Outcome":1,"ErrorMessage":null,"ErrorStackTrace":null,"DisplayName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: \"WindowsDriver\", expectedType: typeof(Terminal.Gui.Drivers.WindowsDriver))","Messages":[],"ComputerName":"Mac-1751908618930","Duration":"00:00:00.3235148","StartTime":"2025-07-07T17:19:33.437184+00:00","EndTime":"2025-07-07T17:19:33.437184+00:00","Properties":[]}],"TestRunStatistics":{"ExecutedTests":182,"Stats":{"Passed":182}},"ActiveTests":[{"Id":"19cdf3d2-6eaa-7423-0871-bce0cc6eeab5","FullyQualifiedName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver","DisplayName":"Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: \"NetDriver\", expectedType: typeof(Terminal.Gui.Drivers.NetDriver))","ExecutorUri":"executor://xunit/VsTestRunner2/netcoreapp","Source":"/Users/runner/work/Terminal.Gui/Terminal.Gui/Tests/UnitTests/bin/Debug/net8.0/UnitTests.dll","CodeFilePath":null,"LineNumber":0,"Properties":[]}]}}
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.610, 214126918291, vstest.console.dll, TestRunRequest:SendTestRunStatsChange: Starting.
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.611, 214126989166, vstest.console.dll, InProgress is Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: "NetDriver", expectedType: typeof(Terminal.Gui.Drivers.NetDriver))
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.611, 214127522958, vstest.console.dll, MulticastDelegateUtilities.SafeInvoke: TestRun.RunStatsChanged: Invoking callbacks was skipped because there are no subscribers.
TpTrace Information: 0 : 1972, 10, 2025/07/07, 17:19:34.611, 214127550833, vstest.console.dll, TestRunRequest:SendTestRunStatsChange: Completed.
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.611, 214127594125, vstest.console.dll, MulticastDelegateUtilities.SafeInvoke: LengthPrefixCommunicationChannel: MessageReceived: Invoking callback 1/1 for Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestSender+<>c__DisplayClass34_0., took 1 ms.
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:34.611, 214127626833, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 500 ms
TpTrace Verbose: 0 : 1972, 4, 2025/07/07, 17:19:34.611, 214127709958, vstest.console.dll, MulticastDelegateUtilities.SafeInvoke: InternalTestLoggerEvents.SendTestResult: Invoking callback 1/1 for Microsoft.VisualStudio.TestPlatform.CommandLine.Internal.ConsoleLogger., took 0 ms.
TpTrace Verbose: 0 : 1972, 4, 2025/07/07, 17:19:34.611, 214127812791, vstest.console.dll, MulticastDelegateUtilities.SafeInvoke: InternalTestLoggerEvents.SendTestResult: Invoking callback 1/1 for Microsoft.VisualStudio.TestPlatform.CommandLine.Internal.ConsoleLogger., took 0 ms.
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:35.613, 215129210041, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 1001 ms
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:36.615, 216130746416, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 1001 ms
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:37.620, 217135092125, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 1004 ms
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:38.627, 218141465125, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 1001 ms
TpTrace Verbose: 0 : 1972, 10, 2025/07/07, 17:19:39.629, 219143013000, vstest.console.dll, TcpClientExtensions.MessageLoopAsync: Polling on remoteEndPoint: 127.0.0.1:49222 localEndPoint: 127.0.0.1:49221 after 1001 ms

tig added a commit to tig/Terminal.Gui that referenced this pull request Jul 7, 2025
@tig
Copy link
Collaborator

tig commented Jul 7, 2025

@tznind - This breaks View.MouseState.

See Buttons scenario. Note that on both the NumericUpDown and Repeat (press-and-hold) buttons do not have their highlight states updated properly.

WindowsTerminal_0ClGF06j7P

Compare this to v2_develop:

WindowsTerminal_2Wol61o9Ts

I have merged this into #4126, and it wasn't too challenging, but then I noticed this.

@tznind
Copy link
Collaborator Author

tznind commented Jul 7, 2025

Ok cool, I guess just need to wire that 'held down' effect into the event handler for IMouseHeldDown.

Something like setting it to true at start and false at end.

@tznind
Copy link
Collaborator Author

tznind commented Jul 10, 2025

Note that on both the NumericUpDown and Repeat (press-and-hold) buttons do not have their highlight states updated properly.

Should be fixed now in a938fc1

@BDisp
Copy link
Collaborator

BDisp commented Jul 10, 2025

@tznind please change the unit test Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver like below because sometimes the ContinueWith is executed without Application is completely initialized. Normally don't fail in v2win and v2net but fails in the others drivers because Mainloop is null.

    [Theory]
    [InlineData ("v2win", typeof (ConsoleDriverFacade<WindowsConsole.InputRecord>))]
    [InlineData ("v2net", typeof (ConsoleDriverFacade<ConsoleKeyInfo>))]
    [InlineData ("FakeDriver", typeof (FakeDriver))]
    [InlineData ("NetDriver", typeof (NetDriver))]
    [InlineData ("WindowsDriver", typeof (WindowsDriver))]
    [InlineData ("CursesDriver", typeof (CursesDriver))]
    public void Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver (string driverName, Type expectedType)
    {
        Assert.True (ConsoleDriver.RunningUnitTests);

        var result = false;

        Task.Run (() =>
                  {
                      while (!Application.Initialized)
                      {
                          Task.Delay (300).Wait ();
                      }
                  }).ContinueWith (
                                   (t, _) =>
                                   {
                                       // no longer loading
                                       Assert.True (Application.Initialized);
                                       Application.Invoke (() =>
                                                           {
                                                               result = true;
                                                               Application.RequestStop ();
                                                           });
                                   },
                                   TaskScheduler.FromCurrentSynchronizationContext ());

        Application.ForceDriver = driverName;
        Application.Run<TestToplevel> ();
        Assert.NotNull (Application.Driver);
        Assert.Equal (expectedType, Application.Driver?.GetType ());
        Assert.NotNull (Application.Top);
        Assert.False (Application.Top!.Running);
        Application.Top!.Dispose ();
        Shutdown ();
        Assert.True (result);
    }

@tznind
Copy link
Collaborator Author

tznind commented Jul 10, 2025

Code still seems to fail in CI, maybe :

Terminal.Gui.ApplicationTests.ApplicationTests.Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver(driverName: "FakeDriver", expectedType: typeof(Terminal.Gui.Drivers.FakeDriver)) [FAIL]
[xUnit.net 00:01:02.00]       Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException : Method Debug.Fail failed with '
[xUnit.net 00:01:02.00]       ', and was translated to Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException to avoid terminating the process hosting the test.

@BDisp
Copy link
Collaborator

BDisp commented Jul 10, 2025

Try this. It's needed to avoid that another driver is passing by using Application.Initialized as true from the previous driver which will fail by asserting the driver type.

    private readonly object _forceDriverLock = new ();

    [Theory]
    [InlineData ("v2win", typeof (ConsoleDriverFacade<WindowsConsole.InputRecord>))]
    [InlineData ("v2net", typeof (ConsoleDriverFacade<ConsoleKeyInfo>))]
    [InlineData ("FakeDriver", typeof (FakeDriver))]
    [InlineData ("NetDriver", typeof (NetDriver))]
    [InlineData ("WindowsDriver", typeof (WindowsDriver))]
    [InlineData ("CursesDriver", typeof (CursesDriver))]
    public void Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver (string driverName, Type expectedType)
    {
        Assert.True (ConsoleDriver.RunningUnitTests);

        var result = false;

        lock (_forceDriverLock)
        {
            Task.Run (() =>
                      {
                          while (!Application.Initialized)
                          {
                              Task.Delay (300).Wait ();
                          }
                      })
                .ContinueWith (
                               (t, _) =>
                               {
                                   // no longer loading
                                   Assert.True (Application.Initialized);

                                   Application.Invoke (() =>
                                                       {
                                                           result = true;
                                                           Application.RequestStop ();
                                                       });
                               },
                               TaskScheduler.FromCurrentSynchronizationContext ());
        }

        Application.ForceDriver = driverName;
        Application.Run<TestToplevel> ();
        Assert.NotNull (Application.Driver);
        Assert.Equal (expectedType, Application.Driver?.GetType ());
        Assert.NotNull (Application.Top);
        Assert.False (Application.Top!.Running);
        Application.Top!.Dispose ();
        Shutdown ();
        Assert.True (result);
    }

@BDisp
Copy link
Collaborator

BDisp commented Jul 10, 2025

Did you already seen these warnings on all projects?

Duplicate 'PackageVersion' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageVersion' items are: Microsoft.Net.Compilers.Toolset 4.11.0, Microsoft.Net.Compilers.Toolset 4.11.0.

@tznind
Copy link
Collaborator Author

tznind commented Jul 10, 2025

I think the key might be this 28787e8

Without Idle anymore we apparently introduce possibility that even with Timespan.Zero the timeout doesn't show as immediately executing.

@BDisp
Copy link
Collaborator

BDisp commented Jul 10, 2025

Great. This latest change you made fix really it. It seems that if it's zero it may wait until the next timeout. Good catch.
Maybe only -1 would be enough but that way is more accurate.

@tig
Copy link
Collaborator

tig commented Jul 10, 2025

@tznind I just submitted another PR to this PR with some code cleanup and API doc improvements.

Copy link
Collaborator

@tig tig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work!

@tig tig merged commit ec827e9 into gui-cs:v2_develop Jul 10, 2025
11 checks passed
@tznind tznind deleted the logarithmic-timeout branch July 10, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idles are just timeouts with Timespan.Zero v2win/v2net - WantContinuousButtonPressed does not repeat.
3 participants