]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix flakey proced refine tests (Bug#73441)
authorLaurence Warne <laurencewarne@gmail.com>
Sun, 27 Oct 2024 15:50:20 +0000 (16:50 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 5 Nov 2024 11:05:16 +0000 (12:05 +0100)
* test/lisp/proced-tests.el (proced-refine-test)
(proced-refine-with-update-test): Use the much simpler CPU refinement
for testing 'proced-refine'.  The previous tests made the incorrect
assumption that refining on the PID of process A only filtered the
buffer to contain process A and its children, whereas in actuality
the children of process A's children, their children, and so on will
also be shown.
(proced-update-preserves-pid-at-point-test): Mark as unstable.

(cherry picked from commit 7a8ca202c5eeb810e5f86510c3ea46d3ec519222)

test/lisp/proced-tests.el

index 682c132854901f1a40f5e61feae8ea3217d0011a..64f9dd4148a60e6536b8006300a1d2a6a4a3c287 100644 (file)
 
 (defun proced--move-to-column (attribute)
   "Move to the column under ATTRIBUTE in the current proced buffer."
-  (move-to-column (string-match attribute proced-header-line)))
-
-(defun proced--assert-process-valid-pid-refinement (pid)
-  "Fail unless the process at point could be present after a refinement using PID."
-  (proced--move-to-column "PID")
-  (let ((pid-equal (string= pid (word-at-point))))
-    (should
-     (or pid-equal
-         ;; Guard against the unlikely event a platform doesn't support PPID
-         (when (string-match "PPID" proced-header-line)
-           (proced--move-to-column "PPID")
-           (string= pid (word-at-point)))))))
+  (move-to-column (string-match attribute proced-header-line))
+  ;; Sometimes the column entry does not fill the whole column.
+  (while (= (char-after (point)) ?\s) (forward-char)))
+
+(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)))
 
 (ert-deftest proced-format-test ()
   (dolist (format '(short medium long verbose))
      (proced--assert-emacs-pid-in-buffer))))
 
 (ert-deftest proced-refine-test ()
-  ;;(skip-unless (memq system-type '(gnu/linux gnu/kfreebsd darwin)))
   (proced--within-buffer
    'verbose
    'user
-   ;; When refining on PID for process A, a process is kept if and only
-   ;; if its PID is the same as process A, or its parent process is
-   ;; process A.
-   (proced--move-to-column "PID")
-   (let ((pid (word-at-point)))
+   ;; When refining on %CPU for process A, a process is kept if and only
+   ;; if its %CPU is greater than or equal to that of process A.
+   (proced--move-to-column "%CPU")
+   (let ((cpu (thing-at-point 'number)))
      (proced-refine)
      (while (not (eobp))
-       (proced--assert-process-valid-pid-refinement pid)
+       (proced--assert-process-valid-cpu-refinement cpu)
        (forward-line)))))
 
 (ert-deftest proced-refine-with-update-test ()
   (proced--within-buffer
    'verbose
    'user
-   (proced--move-to-column "PID")
-   (let ((pid (word-at-point)))
+   (proced--move-to-column "%CPU")
+   (let ((cpu (thing-at-point 'number)))
      (proced-refine)
      ;; Don't use (proced-update t) since this will reset `proced-process-alist'
      ;; and it's possible the process refined on would have exited by that
      ;; processes again, causing the test to fail.
      (proced-update)
      (while (not (eobp))
-       (proced--assert-process-valid-pid-refinement pid)
+       (proced--assert-process-valid-cpu-refinement cpu)
        (forward-line)))))
 
 (ert-deftest proced-update-preserves-pid-at-point-test ()
+  ;; FIXME: Occasionally the cursor inexplicably changes to the first line which
+  ;; causes the test to file when the line isn't the Emacs process.
+  :tags '(:unstable)
   (proced--within-buffer
    'medium
    'user
            (old-window (get-buffer-window)))
        (select-window new-window)
        (with-current-buffer "*Proced*"
-         (proced-update t t))
+         (proced-update))
        (select-window old-window)
        (should (= pid (proced-pid-at-point)))))))