Subject: Re: bug#73441: 31.0.50; Unstable proced-refine-test failure

From: Laurence Warne <[email-masked]>
Date: Tue, 29 Oct 2024 21:26:12 +0000

Hi Michael,

Sorry it looks like I might have overlooked the case where a process has an
empty column for %CPU.  It sounds a bit strange and I can't reproduce it
(as in a process having a blank entry - though I'm guessing it's platform
dependent), but proced-refine appears to respect processes having a blank
entry for %CPU and include them so I guess it's correct to do so in the
tests too?

In the attached patch I also added an ert-explainer to the proced refine
tests so we should get info on the process that failed if it comes up again.

Thanks, Laurence
From 26c793ef1eb612b4997cc5157d10695f84030903 Mon Sep 17 00:00:00 2001
From: Laurence Warne <[email-masked]>
Date: Tue, 29 Oct 2024 20:19:44 +0000
Subject: [PATCH] Don't fail proced refine tests when CPU is empty (Bug#73441)

* test/lisp/proced-tests.el
(proced--assert-process-valid-cpu-refinement): Return t if the cpu
argument is nil.  'proced-refine' when applied to cpu will include
empty values, so by also checking nil we account for that possibility.
(proced--assert-process-valid-cpu-refinement-explainer): New function
for explaining refinement test failures in greater detail.
---
 test/lisp/proced-tests.el | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/test/lisp/proced-tests.el b/test/lisp/proced-tests.el
index b612e172ffb..59638dd63be 100644
--- a/test/lisp/proced-tests.el
+++ b/test/lisp/proced-tests.el
@@ -50,7 +50,19 @@ proced--move-to-column
 (defun proced--assert-process-valid-cpu-refinement (cpu)
   "Fail unless the process at point could be present after a refinement using CPU."
   (proced--move-to-column "%CPU")
-  (should (>= (thing-at-point 'number) cpu)))
+  (or (null cpu) (>= (thing-at-point 'number) cpu)))
+
+(defun proced--assert-process-valid-cpu-refinement-explainer (cpu)
+  "Explain the result of `proced--assert-process-valid-cpu-refinement'.
+
+CPU is as in `proced--assert-process-valid-cpu-refinement'."
+  `(unexpected-refinement
+    (header-line ,(substring-no-properties (cadr (proced-header-line))))
+    (process ,(thing-at-point 'line t))
+    (refined-value ,cpu)
+    (process-value ,(save-excursion (proced--move-to-column "%CPU") (thing-at-point 'number)))))
+
+(put 'proced--assert-process-valid-cpu-refinement 'ert-explainer #'proced--assert-process-valid-cpu-refinement-explainer)
 
 (ert-deftest proced-format-test ()
   (dolist (format '(short medium long verbose))
@@ -90,7 +102,7 @@ proced-refine-test
    (let ((cpu (thing-at-point 'number)))
      (proced-refine)
      (while (not (eobp))
-       (proced--assert-process-valid-cpu-refinement cpu)
+       (should (proced--assert-process-valid-cpu-refinement cpu))
        (forward-line)))))
 
 (ert-deftest proced-refine-with-update-test ()
@@ -106,7 +118,7 @@ proced-refine-with-update-test
      ;; processes again, causing the test to fail.
      (proced-update)
      (while (not (eobp))
-       (proced--assert-process-valid-cpu-refinement cpu)
+       (should (proced--assert-process-valid-cpu-refinement cpu))
        (forward-line)))))
 
 (ert-deftest proced-update-preserves-pid-at-point-test ()
-- 
2.39.5