From 08491aff0b99e7e7ee04a0310174bc13aa0d1bcd Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Tue, 28 Oct 2014 09:30:01 -0700 Subject: [PATCH] Test registry pruning * lisp/registry.el (registry-prune): Change function to do what the docstring says: return a count of total entries pruned. * lisp/tests/gnustest-registry.el (gnustest-registry-usage-test): Uncomment pruning part of test, and alter to correctly receive number of entries pruned. --- lisp/registry.el | 40 +++++++++++++++++++++------------------- lisp/tests/gnustest-registry.el | 17 ++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lisp/registry.el b/lisp/registry.el index dbc7b51..1d31d2b 100644 --- a/lisp/registry.el +++ b/lisp/registry.el @@ -319,25 +319,27 @@ then removes oldest entries first. Returns the number of deleted entries. If SORTFUN is given, tries to keep entries that sort *higher*. SORTFUN is passed only the two keys so it must look them up directly." - (dolist (collector '(registry-prune-soft-candidates - registry-prune-hard-candidates)) - (let* ((size (registry-size db)) - (collected (funcall collector db)) - (limit (nth 0 collected)) - (candidates (nth 1 collected)) - ;; sort the candidates if SORTFUN was given - (candidates (if sortfun (sort candidates sortfun) candidates)) - (candidates-count (length candidates)) - ;; are we over max-soft? - (prune-needed (> size limit))) - - ;; while we have more candidates than we need to remove... - (while (and (> candidates-count (- size limit)) candidates) - (decf candidates-count) - (setq candidates (cdr candidates))) - - (registry-delete db candidates nil) - (length candidates)))) + (let ((pruned 0)) + (dolist (collector '(registry-prune-soft-candidates + registry-prune-hard-candidates)) + (let* ((size (registry-size db)) + (collected (funcall collector db)) + (limit (nth 0 collected)) + (candidates (nth 1 collected)) + ;; sort the candidates if SORTFUN was given + (candidates (if sortfun (sort candidates sortfun) candidates)) + (candidates-count (length candidates)) + ;; are we over max-soft? + (prune-needed (> size limit))) + + ;; while we have more candidates than we need to remove... + (while (and (> candidates-count (- size limit)) candidates) + (decf candidates-count) + (setq candidates (cdr candidates))) + + (registry-delete db candidates nil) + (setq pruned (+ candidates-count pruned)))) + pruned)) (defmethod registry-prune-soft-candidates ((db registry-db)) "Collects pruning candidates from the registry-db object THIS. diff --git a/lisp/tests/gnustest-registry.el b/lisp/tests/gnustest-registry.el index 174a0cb..7fa0498 100644 --- a/lisp/tests/gnustest-registry.el +++ b/lisp/tests/gnustest-registry.el @@ -101,15 +101,14 @@ (should (= n (length (registry-search db :all t)))) (message "Secondary search after delete") (should (= n (length (registry-lookup-secondary-value db 'sender "me")))) - ;; (message "Pruning") - ;; (let* ((tokeep (registry-search db :member '((extra "more data")))) - ;; (count (- n (length tokeep))) - ;; (pruned (registry-prune db)) - ;; (prune-count (length pruned))) - ;; (message "Expecting to prune %d entries and pruned %d" - ;; count prune-count) - ;; (should (and (= count 5) - ;; (= count prune-count)))) + (message "Pruning") + (let* ((tokeep (registry-search db :member '((extra "more data")))) + (count (- n (length tokeep))) + (prune-count (registry-prune db))) + (message "Expecting to prune %d entries and pruned %d" + count prune-count) + (should (and (= count 5) + (= count prune-count)))) (message "Done with usage testing."))) (ert-deftest gnustest-registry-persistence-test () -- 2.1.2