summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2021-01-17 14:00:16 +0100
committerPhilipp Stephani <phst@google.com>2021-01-17 14:02:36 +0100
commit1773679af3241919a85d6174b1554070a63cca79 (patch)
treecc5d73f8615beaa9e1bbff36b45516c89c9080b5 /test
parent39a65844e8d67b5ca3bb2d179e899ff99cd85618 (diff)
downloademacs-1773679af3241919a85d6174b1554070a63cca79.tar.gz
Ensure that sentinels are called during 'accept-process-output'.
When we're trying to notify a process about a status change, we need to ignore the SIGCHLD pipe temporarily, otherwise the code would likely not run into the timeout case that's necessary for a status change to happen. * src/process.c (wait_reading_process_output): Ignore the SIGCHLD pipe when notifying a process about a status change. * test/src/process-tests.el (process-tests/sentinel-called) (process-tests/sentinel-with-multiple-processes): New unit tests.
Diffstat (limited to 'test')
-rw-r--r--test/src/process-tests.el53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index dad36426a09..d2a98dc19f2 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -734,5 +734,58 @@ Return nil if that can't be determined."
(match-string-no-properties 1))))))
process-tests--EMFILE-message)
+(ert-deftest process-tests/sentinel-called ()
+ "Check that sentinels are called after processes finish"
+ (let ((echo (executable-find "echo")))
+ (skip-unless echo)
+ (dolist (conn-type '(pipe pty))
+ (ert-info ((format "Connection type: %s" conn-type))
+ (process-tests--with-processes processes
+ (let* ((calls ())
+ (process (make-process
+ :name "echo"
+ :command (list echo "first")
+ :noquery t
+ :connection-type conn-type
+ :coding 'utf-8-unix
+ :sentinel (lambda (process message)
+ (push (list process message)
+ calls)))))
+ (push process processes)
+ (while (accept-process-output process))
+ (should (equal calls
+ (list (list process "finished\n"))))))))))
+
+(ert-deftest process-tests/sentinel-with-multiple-processes ()
+ "Check that sentinels are called in time even when other processes
+have written output."
+ (let ((echo (executable-find "echo"))
+ (bash (executable-find "bash")))
+ (skip-unless echo)
+ (skip-unless bash)
+ (dolist (conn-type '(pipe pty))
+ (ert-info ((format "Connection type: %s" conn-type))
+ (process-tests--with-processes processes
+ (let* ((calls ())
+ (process (make-process
+ :name "echo"
+ :command (list echo "first")
+ :noquery t
+ :connection-type conn-type
+ :coding 'utf-8-unix
+ :sentinel (lambda (process message)
+ (push (list process message)
+ calls)))))
+ (push process processes)
+ (push (make-process
+ :name "bash"
+ :command (list bash "-c" "sleep 10 && echo second")
+ :noquery t
+ :connection-type conn-type)
+ processes)
+ (while (accept-process-output process))
+ (should (equal calls
+ (list (list process "finished\n"))))))))))
+
(provide 'process-tests)
;;; process-tests.el ends here