summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2021-01-23 19:10:22 +0100
committerPhilipp Stephani <phst@google.com>2021-01-23 19:10:22 +0100
commit8dcb19fc5e3afee7a951194a892f4731bee8ed31 (patch)
treee075728994712f1d7d6d80101a504c54f59593a9 /test
parent17fec603709eb879297a4a0ff0c535c00a13066b (diff)
downloademacs-8dcb19fc5e3afee7a951194a892f4731bee8ed31.tar.gz
Add a unit test testing interaction between threads and processes.
This unit test tests that we can call 'accept-process-output' in parallel from multiple threads. * test/src/process-tests.el (process-tests/multiple-threads-waiting): New unit test.
Diffstat (limited to 'test')
-rw-r--r--test/src/process-tests.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 949f73595b4..676e1b1ac32 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -789,6 +789,35 @@ have written output."
(should (equal calls
(list (list process "finished\n"))))))))))
+(ert-deftest process-tests/multiple-threads-waiting ()
+ (skip-unless (fboundp 'make-thread))
+ (with-timeout (60 (ert-fail "Test timed out"))
+ (process-tests--with-processes processes
+ (let ((threads ())
+ (cat (executable-find "cat")))
+ (skip-unless cat)
+ (dotimes (i 10)
+ (let* ((name (format "test %d" i))
+ (process (make-process :name name
+ :command (list cat)
+ :coding 'no-conversion
+ :noquery t
+ :connection-type 'pipe)))
+ (push process processes)
+ (set-process-thread process nil)
+ (push (make-thread
+ (lambda ()
+ (while (accept-process-output process)))
+ name)
+ threads)))
+ (mapc #'process-send-eof processes)
+ (cl-loop for process in processes
+ and thread in threads
+ do
+ (thread-join thread)
+ (should (eq (process-status process) 'exit))
+ (should (eql (process-exit-status process) 0)))))))
+
(defun process-tests--eval (command form)
"Return a command that evaluates FORM in an Emacs subprocess.
COMMAND must be a list returned by