aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2019-02-03 11:07:36 +0100
committerMichael Albinus2019-02-03 11:07:36 +0100
commitb32ac17c32486d8fce0fb9ecd5e09fe324448d3d (patch)
treebe76b6825ea5f8f5fa98ef1359069fe840228324 /test
parent713eece307bf48717b868f21789eed8160ada5ba (diff)
downloademacs-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'.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/tramp-tests.el100
1 files changed, 58 insertions, 42 deletions
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 ()