emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/with-simulated-input 47aa40dbe1 021/134: Handle the case w


From: ELPA Syncer
Subject: [nongnu] elpa/with-simulated-input 47aa40dbe1 021/134: Handle the case where SECS exactly equals a timer's time
Date: Mon, 10 Jan 2022 23:00:00 -0500 (EST)

branch: elpa/with-simulated-input
commit 47aa40dbe115e578f0ed3b01c45a770371589e17
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>

    Handle the case where SECS exactly equals a timer's time
    
    To avoid floating point issues, we just unconditionally add 0.0001 to
    SECS.
---
 tests/test-with-simulated-input.el | 2 +-
 with-simulated-input.el            | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tests/test-with-simulated-input.el 
b/tests/test-with-simulated-input.el
index 273ccffc3d..f533759a8b 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -107,7 +107,7 @@
     (spy-calls-reset 'idle-canary))
   (it "should run idle timers"
     (run-with-idle-timer 500 nil 'idle-canary)
-    (wsi-simulate-idle-time 501)
+    (wsi-simulate-idle-time 500)
     (expect 'idle-canary :to-have-been-called))
   (it "should not run idle times with longer times"
     (run-with-idle-timer 500 nil 'set 'idle-canary)
diff --git a/with-simulated-input.el b/with-simulated-input.el
index e4787cb936..5eb8bdf8c8 100644
--- a/with-simulated-input.el
+++ b/with-simulated-input.el
@@ -247,6 +247,9 @@ though they would run during real idle time."
     (setq secs
           (cl-loop for timer in timer-idle-list
                    maximize (float-time (timer--time timer)))))
+  ;; Add a small fudge factor to deal with SECS being exactly equal to
+  ;; a timer's time, to avoid floating point issues.
+  (setq secs (+ secs 0.0001))
   (cl-loop
    with already-run-timers = nil
    with stop-time = (seconds-to-time secs)
@@ -263,7 +266,7 @@ though they would run during real idle time."
    if (time-less-p wsi-simulated-idle-time
                    (timer--time next-timer))
    do (setq wsi-simulated-idle-time
-                   (timer--time next-timer))
+            (timer--time next-timer))
    when actually-wait
    do (sleep-for (float-time (time-subtract wsi-simulated-idle-time
                                             previous-idle-time)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]