Re: [PATCH] test: test-lib.el: replace sleep-for with sit-for in notmuch-test-wait

Subject: Re: [PATCH] test: test-lib.el: replace sleep-for with sit-for in notmuch-test-wait

Date: Fri, 3 Aug 2012 16:52:16 -0400

To: Tomi Ollila

Cc: notmuch@notmuchmail.org

From: Austin Clements


Code LGTM, but maybe the comment should explain that this is a
workaround for a bug in Emacs, given that both sleep-for and sit-for
are supposed to process process output and run sentinels (which has
been stated in the Elisp reference at least as far back as Emacs 21).
In light of this (and our better understanding of sleep-for and
sit-for from IRC discussions), the commit message is also misleading.

Quoth Tomi Ollila on Aug 03 at  3:16 pm:
> The function `notmuch-test-wait` called `get-buffer-process` and
> `sleep-for` in a loop. On some emacses neither of these cause emacs
> to check whether the process has exited and update it's status
> accordingly. In this case the loop does not exit.
> 
> The function `sit-for` goes into event loop via `read-event` function
> call. `read-event` does not return when process exits but the event
> loop used to determine whether there is keyboard, mouse, etc. event
> updates the process status as a side effect of the (more generic)
> event loop. `sit-for` is used here to restore the event into queue
> in the improbable case `read-event` consumes an event.
> ---
>  test/test-lib.el |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/test/test-lib.el b/test/test-lib.el
> index 5dd6271..d14246a 100644
> --- a/test/test-lib.el
> +++ b/test/test-lib.el
> @@ -38,7 +38,8 @@
>  (defun notmuch-test-wait ()
>    "Wait for process completion."
>    (while (get-buffer-process (current-buffer))
> -    (sleep-for 0.1)))
> +    ;; sit-for visits event loop for process exit notification.
> +    (sit-for 0.1)))
>  
>  (defun test-output (&optional filename)
>    "Save current buffer to file FILENAME.  Default FILENAME is OUTPUT."

Thread: