浏览代码

Fixes #4322 - FluentTests: Forward configurable timeout to GuiTestContext (#4323)

* Initial plan

* Implement configurable startup timeout for GuiTestContext

- Increase default With.Timeout from 30s to 120s (CI-friendly)
- Add timeout parameter to GuiTestContext constructor
- Forward With.Timeout to GuiTestContext in both A() overloads
- Use configurable timeout for _hardStop CancellationTokenSource
- Update boot wait from fixed 10s to use configurable timeout
- Update WaitUntil to use instance timeout instead of static With.Timeout

Co-authored-by: tig <[email protected]>

* Fix code style - add missing spaces in With.cs

Co-authored-by: tig <[email protected]>

* Change timeout back to 30 seconds as requested

Co-authored-by: tig <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tig <[email protected]>
Co-authored-by: Tig <[email protected]>
Copilot 1 月之前
父节点
当前提交
2d84ab4f01
共有 2 个文件被更改,包括 9 次插入6 次删除
  1. 7 4
      Tests/TerminalGuiFluentTesting/GuiTestContext.cs
  2. 2 2
      Tests/TerminalGuiFluentTesting/With.cs

+ 7 - 4
Tests/TerminalGuiFluentTesting/GuiTestContext.cs

@@ -13,7 +13,7 @@ namespace TerminalGuiFluentTesting;
 public class GuiTestContext : IDisposable
 {
     private readonly CancellationTokenSource _cts = new ();
-    private readonly CancellationTokenSource _hardStop = new (With.Timeout);
+    private readonly CancellationTokenSource _hardStop;
     private readonly Task _runTask;
     private Exception? _ex;
     private readonly FakeOutput _output = new ();
@@ -25,9 +25,12 @@ public class GuiTestContext : IDisposable
     private readonly TestDriver _driver;
     private bool _finished;
     private readonly FakeSizeMonitor _fakeSizeMonitor;
+    private readonly TimeSpan _timeout;
 
-    internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height, TestDriver driver, TextWriter? logWriter = null)
+    internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height, TestDriver driver, TextWriter? logWriter = null, TimeSpan? timeout = null)
     {
+        _timeout = timeout ?? TimeSpan.FromSeconds (30);
+        _hardStop = new (_timeout);
         // Remove frame limit
         Application.MaximumIterationsPerSecond = ushort.MaxValue;
 
@@ -104,7 +107,7 @@ public class GuiTestContext : IDisposable
                              _cts.Token);
 
         // Wait for booting to complete with a timeout to avoid hangs
-        if (!booting.WaitAsync (TimeSpan.FromSeconds (10)).Result)
+        if (!booting.WaitAsync (_timeout).Result)
         {
             throw new TimeoutException ("Application failed to start within the allotted time.");
         }
@@ -440,7 +443,7 @@ public class GuiTestContext : IDisposable
 
         while (!condition ())
         {
-            if (sw.Elapsed > With.Timeout)
+            if (sw.Elapsed > _timeout)
             {
                 throw new TimeoutException ("Failed to reach condition within the time limit");
             }

+ 2 - 2
Tests/TerminalGuiFluentTesting/With.cs

@@ -16,7 +16,7 @@ public static class With
     /// <returns></returns>
     public static GuiTestContext A<T> (int width, int height, TestDriver testDriver, TextWriter? logWriter = null) where T : Toplevel, new ()
     {
-        return new (() => new T (), width, height,testDriver,logWriter);
+        return new (() => new T (), width, height, testDriver, logWriter, Timeout);
     }
 
     /// <summary>
@@ -29,7 +29,7 @@ public static class With
     /// <returns></returns>
     public static GuiTestContext A (Func<Toplevel> toplevelFactory, int width, int height, TestDriver testDriver)
     {
-        return new (toplevelFactory, width, height, testDriver);
+        return new (toplevelFactory, width, height, testDriver, null, Timeout);
     }
     /// <summary>
     ///     The global timeout to allow for any given application to run for before shutting down.