Subject: bug#63550: proced-refine-with-update-test is racy

From: Laurence Warne <[email-masked]>
Date: Sat, 27 May 2023 20:14:34 +0100

> These steps seem to provoke a failure of the original test quite reliably
on macOS:

> 1. add the call (sleep-for 1) both before and after (proced-refine), to
widen the windows
> 2. in a different terminal, keep the command

>  while true; do /bin/sleep 2 & sleep 0.1; done

Thanks for this, with the help of these instructions I can reproduce.

> but I think the test should still pass in this case

Sorry I was wrong here, if the process used for the refinement exited
between proced being called, and then `(proced-update t)` being called,
then the whole process list will be shown as proced would skip applying the
refinement.  So I think using (proced-update) instead of (proced-update t)
is the simplest fix since it means `proced-process-alist` will never be
refreshed.  I've re-attached the patch from before, but with a bit more
explanation.

Thanks, Laurence
From dcf854e3e2b78c8978f1a59d81436cdd4f531d48 Mon Sep 17 00:00:00 2001
From: Laurence Warne <[email-masked]>
Date: Sun, 21 May 2023 18:59:43 +0100
Subject: [PATCH] Fix unstable proced test

Fix unstable proced test by omitting the revert parameter in
'proced-update'.  This was caused by the process being refined on
exiting between the initial 'proced' call and the successive
'proced-update' call.  This resulted in proced skipping the refinement
in 'proced-update', causing all processes to be shown again and the
test to fail.

* test/lisp/proced-tests.el (proced-refine-with-update-test): Do not
use revert parameter when calling 'proced-update'.
---
 test/lisp/proced-tests.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/test/lisp/proced-tests.el b/test/lisp/proced-tests.el
index d69414cf43a..cc3da69a3a0 100644
--- a/test/lisp/proced-tests.el
+++ b/test/lisp/proced-tests.el
@@ -89,14 +89,17 @@ proced-refine-test
        (forward-line)))))
 
 (ert-deftest proced-refine-with-update-test ()
-  :tags '(:unstable)   ; There seems to be an update race here.
   (proced--within-buffer
    'medium
    'user
    (proced--move-to-column "PID")
    (let ((pid (word-at-point)))
      (proced-refine)
-     (proced-update t)
+     ;; 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 point.
+     ;; In this case proced will skip the refinement and show all processes again,
+     ;; causing the test to fail.
+     (proced-update)
      (while (not (eobp))
        (proced--move-to-column "PID")
        (should (string= pid (word-at-point)))
-- 
2.30.2