#nullable enable
using Xunit.Abstractions;
namespace ApplicationTests.Timeout;
///
/// 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().
///
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 ();
// The timeout should have fired
Assert.True (timeoutFired);
app.Dispose ();
}
}