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

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

[elpa] externals/plz 94b5253968 2/3: Fix: (plz-run) Only run FINALLY afe


From: ELPA Syncer
Subject: [elpa] externals/plz 94b5253968 2/3: Fix: (plz-run) Only run FINALLY afer queue is empty
Date: Sat, 15 Apr 2023 22:58:27 -0400 (EDT)

branch: externals/plz
commit 94b52539685d2d6607f437246a5353542800e295
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Fix: (plz-run) Only run FINALLY afer queue is empty
    
    Also fix the queue-related tests.
---
 README.org        |  3 ++-
 plz.el            |  4 +++-
 plz.info          | 30 ++++++++++++++++--------------
 tests/test-plz.el | 30 ++++++++++++++++++------------
 4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/README.org b/README.org
index db455c13bd..a7af8c9fda 100644
--- a/README.org
+++ b/README.org
@@ -175,7 +175,8 @@ You may also clear a queue with ~plz-clear~, which cancels 
any active or queued
 
 ** 0.5.4-pre
 
-Nothing new yet.
+*Fixes*
++ Only run queue's ~finally~ function after queue is empty.  (New features 
should not be designed and released on a Friday.)
 
 ** 0.5.3
 
diff --git a/plz.el b/plz.el
index 2f38603695..fdc45bb334 100644
--- a/plz.el
+++ b/plz.el
@@ -620,7 +620,9 @@ QUEUE should be a `plz-queue' structure."
           (setf args (plist-put args :timeout timeout)))
         (setf (plz-queued-request-process request) (apply #'plz args))
         (push request (plz-queue-active queue))))
-    (when (plz-queue-finally queue)
+    (when (and (plz-queue-finally queue)
+               (zerop (length (plz-queue-active queue)))
+               (zerop (length (plz-queue-requests queue))))
       (funcall (plz-queue-finally queue)))
     queue))
 
diff --git a/plz.info b/plz.info
index fe62b96e63..591df17d56 100644
--- a/plz.info
+++ b/plz.info
@@ -292,7 +292,9 @@ File: README.info,  Node: 054-pre,  Next: 053,  Up: 
Changelog
 3.1 0.5.4-pre
 =============
 
-Nothing new yet.
+*Fixes*
+   • Only run queue’s ‘finally’ function after queue is empty.  (New
+     features should not be designed and released on a Friday.)
 
 
 File: README.info,  Node: 053,  Next: 052,  Prev: 054-pre,  Up: Changelog
@@ -469,19 +471,19 @@ Node: Queueing6723
 Node: Tips7981
 Node: Changelog8282
 Node: 054-pre8529
-Node: 0538641
-Node: 0528961
-Node: 0519168
-Node: 059420
-Node: 049626
-Node: 0310532
-Node: 02110980
-Node: 0211129
-Node: 0111258
-Node: Credits11354
-Node: Development11720
-Node: Copyright assignment12234
-Node: License12822
+Node: 0538773
+Node: 0529093
+Node: 0519300
+Node: 059552
+Node: 049758
+Node: 0310664
+Node: 02111112
+Node: 0211261
+Node: 0111390
+Node: Credits11486
+Node: Development11852
+Node: Copyright assignment12366
+Node: License12954
 
 End Tag Table
 
diff --git a/tests/test-plz.el b/tests/test-plz.el
index 2d32ae6115..05001435ef 100644
--- a/tests/test-plz.el
+++ b/tests/test-plz.el
@@ -508,27 +508,33 @@
 ;; TODO: Test that limit is enforced (though it seems to work fine).
 
 (plz-deftest plz-queue-with-finally ()
-  "Ensure that a queue with a FINALLY function calls it when done."
-  (let* ((finally-called nil)
+  "Ensure that a queue with a FINALLY function calls it correctly.
+That is, that the function is called after the queue is emptied,
+and only called once."
+  (let* ((finally-called-at nil)
+         (finally-called-times 0)
          (queue (make-plz-queue :limit 2
                                 :finally (lambda ()
-                                           (setf finally-called t))))
-         (urls '("https://httpbin.org/get?foo=0";
-                 "https://httpbin.org/get?foo=1";))
-         completed-urls)
+                                           (setf finally-called-at 
(current-time))
+                                           (cl-incf finally-called-times))))
+         (urls '("https://httpbin.org/delay/2";))
+         completed-urls queue-started-at)
     (dolist (url urls)
       (plz-queue queue
         'get url :then (lambda (_)
                          (push url completed-urls))))
+    (setf queue-started-at (current-time))
     (plz-run queue)
     (cl-loop with waits = 0
-             while (and (plz-queue-active queue) (< waits 20))
+             while (and (plz-queue-active queue) (< waits 60))
              do (progn
                   (sleep-for 0.1)
                   (cl-incf waits)))
-    (and (seq-set-equal-p urls completed-urls)
-         (zerop (plz-length queue))
-         finally-called)))
+    (should (seq-set-equal-p urls completed-urls))
+    (should (zerop (plz-length queue)))
+    (should (= 1 finally-called-times))
+    (should (>= (float-time (time-subtract finally-called-at queue-started-at))
+                2))))
 
 (plz-deftest plz-queue-without-finally ()
   "Ensure that a queue without a FINALLY function doesn't signal an error."
@@ -546,8 +552,8 @@
              do (progn
                   (sleep-for 0.1)
                   (cl-incf waits)))
-    (and (seq-set-equal-p urls completed-urls)
-         (zerop (plz-length queue)))))
+    (should (seq-set-equal-p urls completed-urls))
+    (should (zerop (plz-length queue)))))
 
 ;; TODO: Add test for canceling queue.
 



reply via email to

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