Explorar el Código

Revert incorrect FIFO fix - logic was inverted causing LIFO

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] hace 1 mes
padre
commit
ce46e71c40

+ 8 - 18
Terminal.Gui/App/Timeout/TimedEvents.cs

@@ -133,33 +133,24 @@ public class TimedEvents : ITimedEvents
                 k -= 100;
             }
 
-            _timeouts.Add (NudgeToUniqueKey (k, time == TimeSpan.Zero), timeout);
+            _timeouts.Add (NudgeToUniqueKey (k), timeout);
             Added?.Invoke (this, new (timeout, k));
         }
     }
 
     /// <summary>
-    ///     Finds the closest number to <paramref name="k"/> that is not present in <see cref="_timeouts"/>.
-    ///     For immediate execution timeouts (decrementForImmediate=true), decrements to maintain FIFO order.
-    ///     For delayed timeouts, increments to maintain order.
+    ///     Finds the closest number to <paramref name="k"/> that is not present in <see cref="_timeouts"/>
+    ///     (incrementally).
     /// </summary>
-    /// <param name="k">The initial key to try</param>
-    /// <param name="decrementForImmediate">If true, decrements on collision; otherwise increments</param>
-    /// <returns>A unique key</returns>
-    private long NudgeToUniqueKey (long k, bool decrementForImmediate)
+    /// <param name="k"></param>
+    /// <returns></returns>
+    private long NudgeToUniqueKey (long k)
     {
         lock (_timeoutsLockToken)
         {
             while (_timeouts.ContainsKey (k))
             {
-                if (decrementForImmediate)
-                {
-                    k--;
-                }
-                else
-                {
-                    k++;
-                }
+                k++;
             }
         }
 
@@ -194,8 +185,7 @@ public class TimedEvents : ITimedEvents
             {
                 lock (_timeoutsLockToken)
                 {
-                    // When re-adding non-executed timeouts, increment on collision to maintain original order
-                    _timeouts.Add (NudgeToUniqueKey (k, decrementForImmediate: false), timeout);
+                    _timeouts.Add (NudgeToUniqueKey (k), timeout);
                 }
             }
         }

+ 0 - 29
Tests/UnitTests/Application/MainLoopTests.cs

@@ -661,35 +661,6 @@ public class MainLoopTests
 
         Application.Shutdown ();
     }
-
-    [Fact]
-    public void TimeSpanZero_Timeouts_Execute_In_FIFO_Order ()
-    {
-        var ml = new MainLoop (new FakeMainLoop ());
-        var executionOrder = new List<int> ();
-
-        // Add multiple timeouts with TimeSpan.Zero in quick succession
-        // They should execute in the order they were added (FIFO)
-        for (int i = 0; i < 10; i++)
-        {
-            int capturedI = i;
-            ml.TimedEvents.Add (TimeSpan.Zero, () =>
-                                                {
-                                                    executionOrder.Add (capturedI);
-                                                    return false; // Don't repeat
-                                                });
-        }
-
-        // Run one iteration to execute all pending timeouts
-        ml.RunIteration ();
-
-        // Verify they executed in FIFO order (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
-        Assert.Equal (10, executionOrder.Count);
-        for (int i = 0; i < 10; i++)
-        {
-            Assert.Equal (i, executionOrder [i]);
-        }
-    }
     
     [Fact]
     public void RemoveIdle_Function_NotCalled ()