Gnus development mailing list
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: ding@gnus.org
Subject: Re: [PATCH] Two issues with the gnus-registry
Date: Tue, 28 Oct 2014 11:04:44 -0700	[thread overview]
Message-ID: <87h9yogjer.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87zjchxr1v.fsf@ericabrahamsen.net>

[-- Attachment #1: Type: text/plain, Size: 857 bytes --]

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Ted Zlatanov <tzz@lifelogs.com> writes:

[...]

>> The registry has ERT tests, which I thought covered this case.  Can you
>> look at `tests/gnustest-registry.el'?  As a first step, can you try
>> making tests to demonstrate the problems?
>
> Will do.

Okay, turns out there were tests, but the bit that tests pruning was
commented out :)

This is the first in a (gradual) series of patches. It does very little
except:

1. Adjust `registry-prune' to do what the docstring says: return the
total number of entries pruned

2. Uncomment the pruning test and adjust it so it correctly catches the
number of pruned entries.

Test should fail. Over the next couple of days I'll add another test to
check that entries are sorted correctly before pruning, and then take a
stab at fixing the pruning itself.

E


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Test-registry-pruning.patch --]
[-- Type: text/x-diff, Size: 3991 bytes --]

From 08491aff0b99e7e7ee04a0310174bc13aa0d1bcd Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
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


  reply	other threads:[~2014-10-28 18:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 19:04 Eric Abrahamsen
2014-10-24 20:56 ` Eric Abrahamsen
2014-10-25 19:59   ` Eric Abrahamsen
2014-10-27 15:03 ` Ted Zlatanov
2014-10-27 19:15   ` Eric Abrahamsen
2014-10-28 18:04     ` Eric Abrahamsen [this message]
2014-11-07 23:56       ` Eric Abrahamsen
2014-11-08  0:01         ` Eric Abrahamsen
2014-11-08  8:39           ` Eric Abrahamsen
2014-11-10 13:54             ` Ted Zlatanov
2014-11-11  2:55               ` Eric Abrahamsen
2014-11-13 12:05               ` Eric Abrahamsen
2014-11-16  1:04                 ` Dan Christensen
2014-11-16  3:24                   ` Eric Abrahamsen
2014-12-18 10:07                 ` Ted Zlatanov
2014-12-18 15:00                   ` Eric Abrahamsen
2014-12-18 15:09                     ` Eric Abrahamsen
2014-12-19  0:44                       ` Katsumi Yamaoka
2014-12-19  2:08                         ` Eric Abrahamsen
2014-12-20  3:09                         ` Ted Zlatanov
2014-12-20 11:22                           ` Katsumi Yamaoka
2014-12-20 13:53                             ` Older Emacsen (was: [PATCH] Two issues with the gnus-registry) Ted Zlatanov
2014-12-19  1:30                       ` [PATCH] Two issues with the gnus-registry Ted Zlatanov
2014-10-28 20:10     ` Ted Zlatanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h9yogjer.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).