mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +01:00
WIP: submitting #4429
This commit is contained in:
51
Tests/UnitTestsParallelizable/Application/TimeoutTests.cs
Normal file
51
Tests/UnitTestsParallelizable/Application/TimeoutTests.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#nullable enable
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace ApplicationTests.Timeout;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for timeout behavior with nested Application.Run() calls.
|
||||
/// These tests verify that timeouts scheduled in a parent run loop continue to fire
|
||||
/// correctly when a nested modal dialog is shown via Application.Run().
|
||||
/// </summary>
|
||||
public class TimeoutTests (ITestOutputHelper output)
|
||||
{
|
||||
[Fact]
|
||||
public void AddTimeout_Fires ()
|
||||
{
|
||||
IApplication app = Application.Create ();
|
||||
app.Init ("fake");
|
||||
|
||||
uint timeoutTime = 100;
|
||||
var timeoutFired = false;
|
||||
|
||||
// Setup a timeout that will fire
|
||||
app.AddTimeout (
|
||||
TimeSpan.FromMilliseconds (timeoutTime),
|
||||
() =>
|
||||
{
|
||||
timeoutFired = true;
|
||||
|
||||
// Return false so the timer does not repeat
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
// The timeout has not fired yet
|
||||
Assert.False (timeoutFired);
|
||||
|
||||
// Block the thread to prove the timeout does not fire on a background thread
|
||||
Thread.Sleep ((int)timeoutTime * 2);
|
||||
Assert.False (timeoutFired);
|
||||
|
||||
app.StopAfterFirstIteration = true;
|
||||
app.Run<Runnable> ();
|
||||
|
||||
// The timeout should have fired
|
||||
Assert.True (timeoutFired);
|
||||
|
||||
app.Dispose ();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user