diff options
| author | Michael Albinus | 2019-02-03 11:07:36 +0100 |
|---|---|---|
| committer | Michael Albinus | 2019-02-03 11:07:36 +0100 |
| commit | b32ac17c32486d8fce0fb9ecd5e09fe324448d3d (patch) | |
| tree | be76b6825ea5f8f5fa98ef1359069fe840228324 | |
| parent | 713eece307bf48717b868f21789eed8160ada5ba (diff) | |
| download | emacs-b32ac17c32486d8fce0fb9ecd5e09fe324448d3d.tar.gz emacs-b32ac17c32486d8fce0fb9ecd5e09fe324448d3d.zip | |
Work on accept-process-output in Tramp
* lisp/net/tramp.el (tramp-accept-process-output): Rework timer
handling.
(tramp-call-process): Adapt VEC if nil.
(tramp-interrupt-process): Use `tramp-accept-process-output'.
(tramp-process-lines): New defun.
* lisp/net/tramp-adb.el (tramp-adb-parse-device-names):
* lisp/net/tramp-rclone.el (tramp-rclone-parse-device-names): Use it.
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-notify-add-watch):
Use timeout 0 in `tramp-accept-process-output'.
* test/lisp/net/tramp-tests.el (tramp--test-timeout-handler): Move up.
(tramp-test29-start-file-process, tramp-test30-make-process)
(tramp-test32-shell-command)
(tramp--test-shell-command-to-string-asynchronously): Use it.
(tramp-test35-remote-path): Suppress warning.
(tramp--test-asynchronous-requests-timeout): New defconst.
(tramp-test43-asynchronous-requests): Skip if not the only test.
Use `tramp--test-asynchronous-requests-timeout'.
Remove instrumentation. Use `start-process-shell-command' for
watchdog. Add timeout in timer function. Print status messages.
Remove file operations from sentinel. Suppress timers in
`accept-process-output'.
| -rw-r--r-- | lisp/net/tramp-adb.el | 38 | ||||
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-rclone.el | 24 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 32 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 100 |
5 files changed, 100 insertions, 96 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index d45695cbecc..b9b1e4aab6c 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -191,36 +191,14 @@ pass to the OPERATION." | |||
| 191 | ;;;###tramp-autoload | 191 | ;;;###tramp-autoload |
| 192 | (defun tramp-adb-parse-device-names (_ignore) | 192 | (defun tramp-adb-parse-device-names (_ignore) |
| 193 | "Return a list of (nil host) tuples allowed to access." | 193 | "Return a list of (nil host) tuples allowed to access." |
| 194 | (with-timeout (10) | 194 | (delq nil |
| 195 | (with-temp-buffer | 195 | (mapcar |
| 196 | ;; `call-process' does not react on timer under MS Windows. | 196 | (lambda (line) |
| 197 | ;; That's why we use `start-process'. | 197 | (when (string-match "^\\(\\S-+\\)[[:space:]]+device$" line) |
| 198 | ;; We don't know yet whether we need a user or host name for the | 198 | ;; Replace ":" by "#". |
| 199 | ;; connection vector. We assume we don't, it will be OK in most | 199 | `(nil ,(replace-regexp-in-string |
| 200 | ;; of the cases. Otherwise, there might be an additional trace | 200 | ":" tramp-prefix-port-format (match-string 1 line))))) |
| 201 | ;; buffer, which doesn't hurt. | 201 | (tramp-process-lines nil tramp-adb-program "devices")))) |
| 202 | (let ((p (start-process | ||
| 203 | tramp-adb-program (current-buffer) tramp-adb-program "devices")) | ||
| 204 | (v (make-tramp-file-name :method tramp-adb-method)) | ||
| 205 | result) | ||
| 206 | (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " ")) | ||
| 207 | (process-put p 'adjust-window-size-function 'ignore) | ||
| 208 | (set-process-query-on-exit-flag p nil) | ||
| 209 | (while (accept-process-output p nil nil t)) | ||
| 210 | (tramp-message v 6 "\n%s" (buffer-string)) | ||
| 211 | (goto-char (point-min)) | ||
| 212 | (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t) | ||
| 213 | (push (list nil (match-string 1)) result)) | ||
| 214 | |||
| 215 | ;; Replace ":" by "#". | ||
| 216 | (mapc | ||
| 217 | (lambda (elt) | ||
| 218 | (setcar | ||
| 219 | (cdr elt) | ||
| 220 | (replace-regexp-in-string | ||
| 221 | ":" tramp-prefix-port-format (car (cdr elt))))) | ||
| 222 | result) | ||
| 223 | result)))) | ||
| 224 | 202 | ||
| 225 | (defun tramp-adb-handle-file-system-info (filename) | 203 | (defun tramp-adb-handle-file-system-info (filename) |
| 226 | "Like `file-system-info' for Tramp files." | 204 | "Like `file-system-info' for Tramp files." |
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 1f1454925ca..bc45acd3ce6 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -1186,7 +1186,7 @@ If FILE-SYSTEM is non-nil, return file system attributes." | |||
| 1186 | (set-process-filter p 'tramp-gvfs-monitor-process-filter) | 1186 | (set-process-filter p 'tramp-gvfs-monitor-process-filter) |
| 1187 | ;; There might be an error if the monitor is not supported. | 1187 | ;; There might be an error if the monitor is not supported. |
| 1188 | ;; Give the filter a chance to read the output. | 1188 | ;; Give the filter a chance to read the output. |
| 1189 | (while (tramp-accept-process-output p)) | 1189 | (while (tramp-accept-process-output p 0)) |
| 1190 | (unless (process-live-p p) | 1190 | (unless (process-live-p p) |
| 1191 | (tramp-error | 1191 | (tramp-error |
| 1192 | p 'file-notify-error "Monitoring not supported for `%s'" file-name)) | 1192 | p 'file-notify-error "Monitoring not supported for `%s'" file-name)) |
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index 77ff6d59a59..9f46adb4da6 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el | |||
| @@ -171,24 +171,12 @@ pass to the OPERATION." | |||
| 171 | (defun tramp-rclone-parse-device-names (_ignore) | 171 | (defun tramp-rclone-parse-device-names (_ignore) |
| 172 | "Return a list of (nil host) tuples allowed to access." | 172 | "Return a list of (nil host) tuples allowed to access." |
| 173 | (with-tramp-connection-property nil "rclone-device-names" | 173 | (with-tramp-connection-property nil "rclone-device-names" |
| 174 | (with-timeout (10) | 174 | (delq nil |
| 175 | (with-temp-buffer | 175 | (mapcar |
| 176 | ;; `call-process' does not react on timer under MS Windows. | 176 | (lambda (line) |
| 177 | ;; That's why we use `start-process'. | 177 | (when (string-match "^\\(\\S-+\\):$" line) |
| 178 | (let ((p (start-process | 178 | `(nil ,(match-string 1 line)))) |
| 179 | tramp-rclone-program (current-buffer) | 179 | (tramp-process-lines nil tramp-rclone-program "listremotes"))))) |
| 180 | tramp-rclone-program "listremotes")) | ||
| 181 | (v (make-tramp-file-name :method tramp-rclone-method)) | ||
| 182 | result) | ||
| 183 | (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " ")) | ||
| 184 | (process-put p 'adjust-window-size-function 'ignore) | ||
| 185 | (set-process-query-on-exit-flag p nil) | ||
| 186 | (while (accept-process-output p nil nil t)) | ||
| 187 | (tramp-message v 6 "\n%s" (buffer-string)) | ||
| 188 | (goto-char (point-min)) | ||
| 189 | (while (search-forward-regexp "^\\(\\S-+\\):$" nil t) | ||
| 190 | (push (list nil (match-string 1)) result)) | ||
| 191 | result))))) | ||
| 192 | 180 | ||
| 193 | 181 | ||
| 194 | ;; File name primitives. | 182 | ;; File name primitives. |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 54a84ca122f..b1c06690481 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -4111,15 +4111,18 @@ for process communication also." | |||
| 4111 | (let ((inhibit-read-only t) | 4111 | (let ((inhibit-read-only t) |
| 4112 | last-coding-system-used | 4112 | last-coding-system-used |
| 4113 | ;; We do not want to run timers. | 4113 | ;; We do not want to run timers. |
| 4114 | (stimers (with-timeout-suspend)) | ||
| 4114 | timer-list timer-idle-list | 4115 | timer-list timer-idle-list |
| 4115 | result) | 4116 | result) |
| 4116 | ;; JUST-THIS-ONE is set due to Bug#12145. It is an integer, in | 4117 | ;; JUST-THIS-ONE is set due to Bug#12145. |
| 4117 | ;; order to avoid running timers. | ||
| 4118 | (tramp-message | 4118 | (tramp-message |
| 4119 | proc 10 "%s %s %s %s\n%s" | 4119 | proc 10 "%s %s %s %s\n%s" |
| 4120 | proc timeout (process-status proc) | 4120 | proc timeout (process-status proc) |
| 4121 | (setq result (accept-process-output proc timeout nil 0)) | 4121 | (with-local-quit |
| 4122 | (setq result (accept-process-output proc timeout nil t))) | ||
| 4122 | (buffer-string)) | 4123 | (buffer-string)) |
| 4124 | ;; Reenable the timers. | ||
| 4125 | (with-timeout-unsuspend stimers) | ||
| 4123 | result))) | 4126 | result))) |
| 4124 | 4127 | ||
| 4125 | (defun tramp-check-for-regexp (proc regexp) | 4128 | (defun tramp-check-for-regexp (proc regexp) |
| @@ -4640,6 +4643,7 @@ PROGRAM is nil is trapped also, returning 1. Furthermore, traces | |||
| 4640 | are written with verbosity of 6." | 4643 | are written with verbosity of 6." |
| 4641 | (let ((default-directory (tramp-compat-temporary-file-directory)) | 4644 | (let ((default-directory (tramp-compat-temporary-file-directory)) |
| 4642 | (destination (if (eq destination t) (current-buffer) destination)) | 4645 | (destination (if (eq destination t) (current-buffer) destination)) |
| 4646 | (vec (or vec (car tramp-current-connection))) | ||
| 4643 | output error result) | 4647 | output error result) |
| 4644 | (tramp-message | 4648 | (tramp-message |
| 4645 | vec 6 "`%s %s' %s %s" | 4649 | vec 6 "`%s %s' %s %s" |
| @@ -4694,6 +4698,25 @@ are written with verbosity of 6." | |||
| 4694 | (tramp-message vec 6 "%d\n%s" result (error-message-string err)))) | 4698 | (tramp-message vec 6 "%d\n%s" result (error-message-string err)))) |
| 4695 | result)) | 4699 | result)) |
| 4696 | 4700 | ||
| 4701 | (defun tramp-process-lines | ||
| 4702 | (vec program &rest args) | ||
| 4703 | "Calls `process-lines' on the local host. | ||
| 4704 | If an error occurs, it returns nil. Traces are written with | ||
| 4705 | verbosity of 6." | ||
| 4706 | (let ((default-directory (tramp-compat-temporary-file-directory)) | ||
| 4707 | (vec (or vec (car tramp-current-connection))) | ||
| 4708 | result) | ||
| 4709 | (if args | ||
| 4710 | (tramp-message vec 6 "%s %s" program (mapconcat 'identity args " ")) | ||
| 4711 | (tramp-message vec 6 "%s" program)) | ||
| 4712 | (setq result | ||
| 4713 | (condition-case err | ||
| 4714 | (apply 'process-lines program args) | ||
| 4715 | (error | ||
| 4716 | (tramp-error vec (car err) (cdr err))))) | ||
| 4717 | (tramp-message vec 6 "%s" result) | ||
| 4718 | result)) | ||
| 4719 | |||
| 4697 | (defun tramp-read-passwd (proc &optional prompt) | 4720 | (defun tramp-read-passwd (proc &optional prompt) |
| 4698 | "Read a password from user (compat function). | 4721 | "Read a password from user (compat function). |
| 4699 | Consults the auth-source package. | 4722 | Consults the auth-source package. |
| @@ -4852,8 +4875,7 @@ Only works for Bourne-like shells." | |||
| 4852 | ;; Wait, until the process has disappeared. If it doesn't, | 4875 | ;; Wait, until the process has disappeared. If it doesn't, |
| 4853 | ;; fall back to the default implementation. | 4876 | ;; fall back to the default implementation. |
| 4854 | (with-timeout (1 (ignore)) | 4877 | (with-timeout (1 (ignore)) |
| 4855 | ;; We cannot run `tramp-accept-process-output', it blocks timers. | 4878 | (while (tramp-accept-process-output proc)) |
| 4856 | (while (accept-process-output proc nil nil t)) | ||
| 4857 | ;; Report success. | 4879 | ;; Report success. |
| 4858 | proc))))) | 4880 | proc))))) |
| 4859 | 4881 | ||
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 129ffe9eee7..dccef81b7b5 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -3798,6 +3798,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3798 | ;; Cleanup. | 3798 | ;; Cleanup. |
| 3799 | (ignore-errors (delete-file tmp-name)))))) | 3799 | (ignore-errors (delete-file tmp-name)))))) |
| 3800 | 3800 | ||
| 3801 | ;; Must be a command, because used as `sigusr' handler. | ||
| 3802 | (defun tramp--test-timeout-handler (&rest _ignore) | ||
| 3803 | "Timeout handler, reporting a failed test." | ||
| 3804 | (interactive) | ||
| 3805 | (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test))))) | ||
| 3806 | |||
| 3801 | (ert-deftest tramp-test29-start-file-process () | 3807 | (ert-deftest tramp-test29-start-file-process () |
| 3802 | "Check `start-file-process'." | 3808 | "Check `start-file-process'." |
| 3803 | :tags '(:expensive-test) | 3809 | :tags '(:expensive-test) |
| @@ -3816,7 +3822,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3816 | (process-send-string proc "foo") | 3822 | (process-send-string proc "foo") |
| 3817 | (process-send-eof proc) | 3823 | (process-send-eof proc) |
| 3818 | ;; Read output. | 3824 | ;; Read output. |
| 3819 | (with-timeout (10 (ert-fail "`start-file-process' timed out")) | 3825 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3820 | (while (< (- (point-max) (point-min)) (length "foo")) | 3826 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3821 | (while (accept-process-output proc 0 nil t)))) | 3827 | (while (accept-process-output proc 0 nil t)))) |
| 3822 | (should (string-equal (buffer-string) "foo"))) | 3828 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3834,7 +3840,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3834 | "cat" (file-name-nondirectory tmp-name))) | 3840 | "cat" (file-name-nondirectory tmp-name))) |
| 3835 | (should (processp proc)) | 3841 | (should (processp proc)) |
| 3836 | ;; Read output. | 3842 | ;; Read output. |
| 3837 | (with-timeout (10 (ert-fail "`start-file-process' timed out")) | 3843 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3838 | (while (< (- (point-max) (point-min)) (length "foo")) | 3844 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3839 | (while (accept-process-output proc 0 nil t)))) | 3845 | (while (accept-process-output proc 0 nil t)))) |
| 3840 | (should (string-equal (buffer-string) "foo"))) | 3846 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3855,7 +3861,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3855 | (process-send-string proc "foo") | 3861 | (process-send-string proc "foo") |
| 3856 | (process-send-eof proc) | 3862 | (process-send-eof proc) |
| 3857 | ;; Read output. | 3863 | ;; Read output. |
| 3858 | (with-timeout (10 (ert-fail "`start-file-process' timed out")) | 3864 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3859 | (while (< (- (point-max) (point-min)) (length "foo")) | 3865 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3860 | (while (accept-process-output proc 0 nil t)))) | 3866 | (while (accept-process-output proc 0 nil t)))) |
| 3861 | (should (string-equal (buffer-string) "foo"))) | 3867 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3888,7 +3894,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3888 | (process-send-string proc "foo") | 3894 | (process-send-string proc "foo") |
| 3889 | (process-send-eof proc) | 3895 | (process-send-eof proc) |
| 3890 | ;; Read output. | 3896 | ;; Read output. |
| 3891 | (with-timeout (10 (ert-fail "`make-process' timed out")) | 3897 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3892 | (while (< (- (point-max) (point-min)) (length "foo")) | 3898 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3893 | (while (accept-process-output proc 0 nil t)))) | 3899 | (while (accept-process-output proc 0 nil t)))) |
| 3894 | (should (string-equal (buffer-string) "foo"))) | 3900 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3908,7 +3914,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3908 | :file-handler t)) | 3914 | :file-handler t)) |
| 3909 | (should (processp proc)) | 3915 | (should (processp proc)) |
| 3910 | ;; Read output. | 3916 | ;; Read output. |
| 3911 | (with-timeout (10 (ert-fail "`make-process' timed out")) | 3917 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3912 | (while (< (- (point-max) (point-min)) (length "foo")) | 3918 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3913 | (while (accept-process-output proc 0 nil t)))) | 3919 | (while (accept-process-output proc 0 nil t)))) |
| 3914 | (should (string-equal (buffer-string) "foo"))) | 3920 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3933,7 +3939,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3933 | (process-send-string proc "foo") | 3939 | (process-send-string proc "foo") |
| 3934 | (process-send-eof proc) | 3940 | (process-send-eof proc) |
| 3935 | ;; Read output. | 3941 | ;; Read output. |
| 3936 | (with-timeout (10 (ert-fail "`make-process' timed out")) | 3942 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3937 | (while (< (- (point-max) (point-min)) (length "foo")) | 3943 | (while (< (- (point-max) (point-min)) (length "foo")) |
| 3938 | (while (accept-process-output proc 0 nil t)))) | 3944 | (while (accept-process-output proc 0 nil t)))) |
| 3939 | (should (string-equal (buffer-string) "foo"))) | 3945 | (should (string-equal (buffer-string) "foo"))) |
| @@ -3957,7 +3963,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3957 | (process-send-eof proc) | 3963 | (process-send-eof proc) |
| 3958 | (delete-process proc) | 3964 | (delete-process proc) |
| 3959 | ;; Read output. | 3965 | ;; Read output. |
| 3960 | (with-timeout (10 (ert-fail "`make-process' timed out")) | 3966 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3961 | (while (accept-process-output proc 0 nil t))) | 3967 | (while (accept-process-output proc 0 nil t))) |
| 3962 | (should (string-equal (buffer-string) "killed\n"))) | 3968 | (should (string-equal (buffer-string) "killed\n"))) |
| 3963 | 3969 | ||
| @@ -3977,7 +3983,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3977 | (should (processp proc)) | 3983 | (should (processp proc)) |
| 3978 | ;; Read stderr. | 3984 | ;; Read stderr. |
| 3979 | (with-current-buffer stderr | 3985 | (with-current-buffer stderr |
| 3980 | (with-timeout (10 (ert-fail "`make-process' timed out")) | 3986 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 3981 | (while (= (point-min) (point-max)) | 3987 | (while (= (point-min) (point-max)) |
| 3982 | (while (accept-process-output proc 0 nil t)))) | 3988 | (while (accept-process-output proc 0 nil t)))) |
| 3983 | (should | 3989 | (should |
| @@ -4054,7 +4060,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4054 | (format "ls %s" (file-name-nondirectory tmp-name)) | 4060 | (format "ls %s" (file-name-nondirectory tmp-name)) |
| 4055 | (current-buffer)) | 4061 | (current-buffer)) |
| 4056 | ;; Read output. | 4062 | ;; Read output. |
| 4057 | (with-timeout (10 (ert-fail "`async-shell-command' timed out")) | 4063 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 4058 | (while (accept-process-output | 4064 | (while (accept-process-output |
| 4059 | (get-buffer-process (current-buffer)) nil nil t))) | 4065 | (get-buffer-process (current-buffer)) nil nil t))) |
| 4060 | ;; `ls' could produce colorized output. | 4066 | ;; `ls' could produce colorized output. |
| @@ -4083,7 +4089,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4083 | (get-buffer-process (current-buffer)) | 4089 | (get-buffer-process (current-buffer)) |
| 4084 | (format "%s\n" (file-name-nondirectory tmp-name))) | 4090 | (format "%s\n" (file-name-nondirectory tmp-name))) |
| 4085 | ;; Read output. | 4091 | ;; Read output. |
| 4086 | (with-timeout (10 (ert-fail "`async-shell-command' timed out")) | 4092 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 4087 | (while (accept-process-output | 4093 | (while (accept-process-output |
| 4088 | (get-buffer-process (current-buffer)) nil nil t))) | 4094 | (get-buffer-process (current-buffer)) nil nil t))) |
| 4089 | ;; `ls' could produce colorized output. | 4095 | ;; `ls' could produce colorized output. |
| @@ -4107,7 +4113,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4107 | "Like `shell-command-to-string', but for asynchronous processes." | 4113 | "Like `shell-command-to-string', but for asynchronous processes." |
| 4108 | (with-temp-buffer | 4114 | (with-temp-buffer |
| 4109 | (async-shell-command command (current-buffer)) | 4115 | (async-shell-command command (current-buffer)) |
| 4110 | (with-timeout (10 (ert-fail "`async-shell-command-to-string' timed out")) | 4116 | (with-timeout (10 (tramp--test-timeout-handler)) |
| 4111 | (while (accept-process-output | 4117 | (while (accept-process-output |
| 4112 | (get-buffer-process (current-buffer)) nil nil t))) | 4118 | (get-buffer-process (current-buffer)) nil nil t))) |
| 4113 | (buffer-substring-no-properties (point-min) (point-max)))) | 4119 | (buffer-substring-no-properties (point-min) (point-max)))) |
| @@ -4326,7 +4332,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 4326 | 4332 | ||
| 4327 | (let* ((tmp-name (tramp--test-make-temp-name)) | 4333 | (let* ((tmp-name (tramp--test-make-temp-name)) |
| 4328 | (default-directory tramp-test-temporary-file-directory) | 4334 | (default-directory tramp-test-temporary-file-directory) |
| 4329 | (orig-exec-path (exec-path)) | 4335 | (orig-exec-path (with-no-warnings (exec-path))) |
| 4330 | (tramp-remote-path tramp-remote-path) | 4336 | (tramp-remote-path tramp-remote-path) |
| 4331 | (orig-tramp-remote-path tramp-remote-path)) | 4337 | (orig-tramp-remote-path tramp-remote-path)) |
| 4332 | (unwind-protect | 4338 | (unwind-protect |
| @@ -5204,9 +5210,11 @@ Use the `ls' command." | |||
| 5204 | (numberp (nth 1 fsi)) | 5210 | (numberp (nth 1 fsi)) |
| 5205 | (numberp (nth 2 fsi)))))) | 5211 | (numberp (nth 2 fsi)))))) |
| 5206 | 5212 | ||
| 5207 | (defun tramp--test-timeout-handler () | 5213 | ;; `tramp-test43-asynchronous-requests' could be blocked. So we set a |
| 5208 | "Timeout handler, reporting a failed test." | 5214 | ;; timeout of 300 seconds, and we send a SIGUSR1 signal after 300 |
| 5209 | (ert-fail (format "`%s' timed out" (ert-test-name (ert-running-test))))) | 5215 | ;; seconds. Similar check is performed in the timer function. |
| 5216 | (defconst tramp--test-asynchronous-requests-timeout 300 | ||
| 5217 | "Timeout for `tramp-test43-asynchronous-requests'.") | ||
| 5210 | 5218 | ||
| 5211 | ;; This test is inspired by Bug#16928. | 5219 | ;; This test is inspired by Bug#16928. |
| 5212 | (ert-deftest tramp-test43-asynchronous-requests () | 5220 | (ert-deftest tramp-test43-asynchronous-requests () |
| @@ -5216,26 +5224,27 @@ process sentinels. They shall not disturb each other." | |||
| 5216 | ;; The test fails from time to time, w/o a reproducible pattern. So | 5224 | ;; The test fails from time to time, w/o a reproducible pattern. So |
| 5217 | ;; we mark it as unstable. | 5225 | ;; we mark it as unstable. |
| 5218 | :tags '(:expensive-test :unstable) | 5226 | :tags '(:expensive-test :unstable) |
| 5219 | ;; Recent investigations have uncovered a race condition in | ||
| 5220 | ;; `accept-process-output'. Let's check on emba, whether this has | ||
| 5221 | ;; been solved. | ||
| 5222 | ;; (if (getenv "EMACS_EMBA_CI") '(:expensive-test) '(:expensive-test :unstable)) | ||
| 5223 | (skip-unless (tramp--test-enabled)) | 5227 | (skip-unless (tramp--test-enabled)) |
| 5224 | (skip-unless (tramp--test-sh-p)) | 5228 | (skip-unless (tramp--test-sh-p)) |
| 5229 | ;; This test is sensible wrt to other running tests. Let it work | ||
| 5230 | ;; only if it is the only selected test. | ||
| 5231 | ;; FIXME: There must be a better solution. | ||
| 5232 | (skip-unless | ||
| 5233 | (= 1 (length | ||
| 5234 | (ert-select-tests (ert--stats-selector ert--current-run-stats) t)))) | ||
| 5225 | 5235 | ||
| 5226 | ;; This test could be blocked on hydra. So we set a timeout of 300 | 5236 | (with-timeout |
| 5227 | ;; seconds, and we send a SIGUSR1 signal after 300 seconds. | 5237 | (tramp--test-asynchronous-requests-timeout (tramp--test-timeout-handler)) |
| 5228 | ;; This clearly doesn't work though, because the test not | ||
| 5229 | ;; infrequently hangs for hours until killed by the infrastructure. | ||
| 5230 | (with-timeout (300 (tramp--test-timeout-handler)) | ||
| 5231 | (define-key special-event-map [sigusr1] 'tramp--test-timeout-handler) | 5238 | (define-key special-event-map [sigusr1] 'tramp--test-timeout-handler) |
| 5232 | (tramp--test-instrument-test-case (if (getenv "EMACS_HYDRA_CI") 10 0) | ||
| 5233 | (let* (;; For the watchdog. | 5239 | (let* (;; For the watchdog. |
| 5234 | (default-directory (expand-file-name temporary-file-directory)) | 5240 | (default-directory (expand-file-name temporary-file-directory)) |
| 5241 | (shell-file-name "/bin/sh") | ||
| 5235 | (watchdog | 5242 | (watchdog |
| 5236 | (start-process | 5243 | (start-process-shell-command |
| 5237 | "*watchdog*" nil shell-file-name shell-command-switch | 5244 | "*watchdog*" nil |
| 5238 | (format "sleep 300; kill -USR1 %d" (emacs-pid)))) | 5245 | (format |
| 5246 | "sleep %d; kill -USR1 %d" | ||
| 5247 | tramp--test-asynchronous-requests-timeout (emacs-pid)))) | ||
| 5239 | (tmp-name (tramp--test-make-temp-name)) | 5248 | (tmp-name (tramp--test-make-temp-name)) |
| 5240 | (default-directory tmp-name) | 5249 | (default-directory tmp-name) |
| 5241 | ;; Do not cache Tramp properties. | 5250 | ;; Do not cache Tramp properties. |
| @@ -5263,6 +5272,9 @@ process sentinels. They shall not disturb each other." | |||
| 5263 | (cond | 5272 | (cond |
| 5264 | ((tramp--test-mock-p) 'vc-registered) | 5273 | ((tramp--test-mock-p) 'vc-registered) |
| 5265 | (t 'file-attributes))) | 5274 | (t 'file-attributes))) |
| 5275 | ;; This is when all timers start. We check inside the | ||
| 5276 | ;; timer function, that we don't exceed timeout. | ||
| 5277 | (timer-start (current-time)) | ||
| 5266 | timer buffers kill-buffer-query-functions) | 5278 | timer buffers kill-buffer-query-functions) |
| 5267 | 5279 | ||
| 5268 | (unwind-protect | 5280 | (unwind-protect |
| @@ -5277,6 +5289,9 @@ process sentinels. They shall not disturb each other." | |||
| 5277 | (run-at-time | 5289 | (run-at-time |
| 5278 | 0 timer-repeat | 5290 | 0 timer-repeat |
| 5279 | (lambda () | 5291 | (lambda () |
| 5292 | (when (> (- (time-to-seconds) (time-to-seconds timer-start)) | ||
| 5293 | tramp--test-asynchronous-requests-timeout) | ||
| 5294 | (tramp--test-timeout-handler)) | ||
| 5280 | (when buffers | 5295 | (when buffers |
| 5281 | (let ((time (float-time)) | 5296 | (let ((time (float-time)) |
| 5282 | (default-directory tmp-name) | 5297 | (default-directory tmp-name) |
| @@ -5286,12 +5301,13 @@ process sentinels. They shall not disturb each other." | |||
| 5286 | "Start timer %s %s" file (current-time-string)) | 5301 | "Start timer %s %s" file (current-time-string)) |
| 5287 | (funcall timer-operation file) | 5302 | (funcall timer-operation file) |
| 5288 | ;; Adjust timer if it takes too much time. | 5303 | ;; Adjust timer if it takes too much time. |
| 5304 | (tramp--test-message | ||
| 5305 | "Stop timer %s %s" file (current-time-string)) | ||
| 5289 | (when (> (- (float-time) time) timer-repeat) | 5306 | (when (> (- (float-time) time) timer-repeat) |
| 5290 | (setq timer-repeat (* 1.5 timer-repeat)) | 5307 | (setq timer-repeat (* 1.5 timer-repeat)) |
| 5291 | (setf (timer--repeat-delay timer) timer-repeat) | 5308 | (setf (timer--repeat-delay timer) timer-repeat) |
| 5292 | (tramp--test-message "Increase timer %s" timer-repeat)) | 5309 | (tramp--test-message |
| 5293 | (tramp--test-message | 5310 | "Increase timer %s" timer-repeat))))))) |
| 5294 | "Stop timer %s %s" file (current-time-string))))))) | ||
| 5295 | 5311 | ||
| 5296 | ;; Create temporary buffers. The number of buffers | 5312 | ;; Create temporary buffers. The number of buffers |
| 5297 | ;; corresponds to the number of processes; it could be | 5313 | ;; corresponds to the number of processes; it could be |
| @@ -5307,9 +5323,9 @@ process sentinels. They shall not disturb each other." | |||
| 5307 | (start-file-process-shell-command | 5323 | (start-file-process-shell-command |
| 5308 | (buffer-name buf) buf | 5324 | (buffer-name buf) buf |
| 5309 | (concat | 5325 | (concat |
| 5310 | "(read line && echo $line >$line);" | 5326 | "(read line && echo $line >$line && echo $line);" |
| 5311 | "(read line && cat $line);" | 5327 | "(read line && cat $line);" |
| 5312 | "(read line && rm $line)"))) | 5328 | "(read line && rm -f $line)"))) |
| 5313 | (file (expand-file-name (buffer-name buf)))) | 5329 | (file (expand-file-name (buffer-name buf)))) |
| 5314 | ;; Remember the file name. Add counter. | 5330 | ;; Remember the file name. Add counter. |
| 5315 | (process-put proc 'foo file) | 5331 | (process-put proc 'foo file) |
| @@ -5325,17 +5341,16 @@ process sentinels. They shall not disturb each other." | |||
| 5325 | (unless (zerop (length string)) | 5341 | (unless (zerop (length string)) |
| 5326 | (dired-uncache (process-get proc 'foo)) | 5342 | (dired-uncache (process-get proc 'foo)) |
| 5327 | (should (file-attributes (process-get proc 'foo)))))) | 5343 | (should (file-attributes (process-get proc 'foo)))))) |
| 5328 | ;; Add process sentinel. | 5344 | ;; Add process sentinel. It shall not perform remote |
| 5345 | ;; operations, triggering Tramp processes. This blocks. | ||
| 5329 | (set-process-sentinel | 5346 | (set-process-sentinel |
| 5330 | proc | 5347 | proc |
| 5331 | (lambda (proc _state) | 5348 | (lambda (proc _state) |
| 5332 | (tramp--test-message | 5349 | (tramp--test-message |
| 5333 | "Process sentinel %s %s" proc (current-time-string)) | 5350 | "Process sentinel %s %s" proc (current-time-string)))))) |
| 5334 | (dired-uncache (process-get proc 'foo)) | ||
| 5335 | (should-not (file-attributes (process-get proc 'foo))))))) | ||
| 5336 | 5351 | ||
| 5337 | ;; Send a string. Use a random order of the buffers. Mix | 5352 | ;; Send a string to the processes. Use a random order of |
| 5338 | ;; with regular operation. | 5353 | ;; the buffers. Mix with regular operation. |
| 5339 | (let ((buffers (copy-sequence buffers))) | 5354 | (let ((buffers (copy-sequence buffers))) |
| 5340 | (while buffers | 5355 | (while buffers |
| 5341 | ;; Activate timer. | 5356 | ;; Activate timer. |
| @@ -5375,7 +5390,8 @@ process sentinels. They shall not disturb each other." | |||
| 5375 | (tramp--test-message "Check %s" (current-time-string)) | 5390 | (tramp--test-message "Check %s" (current-time-string)) |
| 5376 | (dolist (buf buffers) | 5391 | (dolist (buf buffers) |
| 5377 | (with-current-buffer buf | 5392 | (with-current-buffer buf |
| 5378 | (should (string-equal (format "%s\n" buf) (buffer-string))))) | 5393 | (should |
| 5394 | (string-equal (format "%s\n%s\n" buf buf) (buffer-string))))) | ||
| 5379 | (should-not | 5395 | (should-not |
| 5380 | (directory-files | 5396 | (directory-files |
| 5381 | tmp-name nil directory-files-no-dot-files-regexp))) | 5397 | tmp-name nil directory-files-no-dot-files-regexp))) |
| @@ -5387,7 +5403,7 @@ process sentinels. They shall not disturb each other." | |||
| 5387 | (ignore-errors (delete-process (get-buffer-process buf))) | 5403 | (ignore-errors (delete-process (get-buffer-process buf))) |
| 5388 | (ignore-errors (kill-buffer buf))) | 5404 | (ignore-errors (kill-buffer buf))) |
| 5389 | (ignore-errors (cancel-timer timer)) | 5405 | (ignore-errors (cancel-timer timer)) |
| 5390 | (ignore-errors (delete-directory tmp-name 'recursive))))))) | 5406 | (ignore-errors (delete-directory tmp-name 'recursive)))))) |
| 5391 | 5407 | ||
| 5392 | ;; This test is inspired by Bug#29163. | 5408 | ;; This test is inspired by Bug#29163. |
| 5393 | (ert-deftest tramp-test44-auto-load () | 5409 | (ert-deftest tramp-test44-auto-load () |