aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2017-06-29 18:22:38 +0200
committerMichael Albinus2017-06-29 18:22:38 +0200
commit138447c3abd749d1c27d99d7089b1b0903352ade (patch)
treef8ab4620eb071453168bacb339766e938b825954 /test
parent3b19663b44be29986ebaacfb3a3c95130cd65964 (diff)
downloademacs-138447c3abd749d1c27d99d7089b1b0903352ade.tar.gz
emacs-138447c3abd749d1c27d99d7089b1b0903352ade.zip
Improve timer handling when Tramp accepts output
* lisp/net/tramp-compat.el: Avoid compiler warning. * lisp/net/tramp-sh.el (tramp-sh-file-name-handler): Remove lock machinery. * lisp/net/tramp.el (tramp-locked, tramp-locker): Move up. (tramp-file-name-handler): Add lock machinery from `tramp-sh-file-name-handler'. Allow timers to run. (tramp-accept-process-output): Remove nasty workaround. Suppress timers. * test/lisp/net/tramp-tests.el (shell-command-sentinel): Suppress run in tests. (tramp--instrument-test-case-p): New defvar. (tramp--instrument-test-case): Use it in order to allow nested calls. (tramp--test-message, tramp--test-backtrace): New defsubst, will be used for occasional test instrumentation. (tramp-test00-availability, tramp-test31-vc-registered): Use them. (tramp-test28-shell-command) (tramp--test-shell-command-to-string-asynchronously): Suppress nasty messages. Don't overwrite sentinel. (tramp-test36-asynchronous-requests): Rewrite major parts. Expect :passed.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/tramp-tests.el231
1 files changed, 140 insertions, 91 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index a90e3fff355..a10b8579032 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -53,6 +53,8 @@
53(defvar tramp-copy-size-limit) 53(defvar tramp-copy-size-limit)
54(defvar tramp-persistency-file-name) 54(defvar tramp-persistency-file-name)
55(defvar tramp-remote-process-environment) 55(defvar tramp-remote-process-environment)
56;; Suppress nasty messages.
57(fset 'shell-command-sentinel 'ignore)
56 58
57;; There is no default value on w32 systems, which could work out of the box. 59;; There is no default value on w32 systems, which could work out of the box.
58(defconst tramp-test-temporary-file-directory 60(defconst tramp-test-temporary-file-directory
@@ -126,29 +128,52 @@ If QUOTED is non-nil, the local part of the file is quoted."
126 (make-temp-name "tramp-test") 128 (make-temp-name "tramp-test")
127 (if local temporary-file-directory tramp-test-temporary-file-directory)))) 129 (if local temporary-file-directory tramp-test-temporary-file-directory))))
128 130
131;; Don't print messages in nested `tramp--instrument-test-case' calls.
132(defvar tramp--instrument-test-case-p nil
133 "Whether `tramp--instrument-test-case' run.
134This shall used dynamically bound only.")
135
129(defmacro tramp--instrument-test-case (verbose &rest body) 136(defmacro tramp--instrument-test-case (verbose &rest body)
130 "Run BODY with `tramp-verbose' equal VERBOSE. 137 "Run BODY with `tramp-verbose' equal VERBOSE.
131Print the the content of the Tramp debug buffer, if BODY does not 138Print the the content of the Tramp debug buffer, if BODY does not
132eval properly in `should' or `should-not'. `should-error' is not 139eval properly in `should' or `should-not'. `should-error' is not
133handled properly. BODY shall not contain a timeout." 140handled properly. BODY shall not contain a timeout."
134 (declare (indent 1) (debug (natnump body))) 141 (declare (indent 1) (debug (natnump body)))
135 `(let ((tramp-verbose ,verbose) 142 `(let ((tramp-verbose (max (or ,verbose 0) (or tramp-verbose 0)))
143 (tramp-message-show-message t)
136 (tramp-debug-on-error t) 144 (tramp-debug-on-error t)
137 (debug-ignored-errors 145 (debug-ignored-errors
138 (cons "^make-symbolic-link not supported$" debug-ignored-errors))) 146 (cons "^make-symbolic-link not supported$" debug-ignored-errors))
147 inhibit-message)
139 (unwind-protect 148 (unwind-protect
140 (progn ,@body) 149 (let ((tramp--instrument-test-case-p t)) ,@body)
141 (when (> tramp-verbose 3) 150 ;; Unwind forms.
151 (when (and (null tramp--instrument-test-case-p) (> tramp-verbose 3))
142 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil 152 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
143 (with-current-buffer (tramp-get-connection-buffer v) 153 (with-current-buffer (tramp-get-connection-buffer v)
144 (message "%s" (buffer-string))) 154 (message "%s" (buffer-string)))
145 (with-current-buffer (tramp-get-debug-buffer v) 155 (with-current-buffer (tramp-get-debug-buffer v)
146 (message "%s" (buffer-string)))))))) 156 (message "%s" (buffer-string))))))))
147 157
158(defsubst tramp--test-message (fmt-string &rest arguments)
159 "Emit a message into ERT *Messages*."
160 (tramp--instrument-test-case 0
161 (apply
162 'tramp-message
163 (tramp-dissect-file-name tramp-test-temporary-file-directory) 0
164 fmt-string arguments)))
165
166(defsubst tramp--test-backtrace ()
167 "Dump a backtrace into ERT *Messages*."
168 (tramp--instrument-test-case 10
169 (tramp-backtrace
170 (tramp-dissect-file-name tramp-test-temporary-file-directory))))
171
148(ert-deftest tramp-test00-availability () 172(ert-deftest tramp-test00-availability ()
149 "Test availability of Tramp functions." 173 "Test availability of Tramp functions."
150 :expected-result (if (tramp--test-enabled) :passed :failed) 174 :expected-result (if (tramp--test-enabled) :passed :failed)
151 (message "Remote directory: `%s'" tramp-test-temporary-file-directory) 175 (tramp--test-message
176 "Remote directory: `%s'" tramp-test-temporary-file-directory)
152 (should (ignore-errors 177 (should (ignore-errors
153 (and 178 (and
154 (file-remote-p tramp-test-temporary-file-directory) 179 (file-remote-p tramp-test-temporary-file-directory)
@@ -2759,6 +2784,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2759 (dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil))) 2784 (dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil)))
2760 (let ((tmp-name (tramp--test-make-temp-name nil quoted)) 2785 (let ((tmp-name (tramp--test-make-temp-name nil quoted))
2761 (default-directory tramp-test-temporary-file-directory) 2786 (default-directory tramp-test-temporary-file-directory)
2787 ;; Suppress nasty messages.
2788 (inhibit-message t)
2762 kill-buffer-query-functions) 2789 kill-buffer-query-functions)
2763 (unwind-protect 2790 (unwind-protect
2764 (with-temp-buffer 2791 (with-temp-buffer
@@ -2787,7 +2814,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2787 (async-shell-command 2814 (async-shell-command
2788 (format "ls %s" (file-name-nondirectory tmp-name)) 2815 (format "ls %s" (file-name-nondirectory tmp-name))
2789 (current-buffer)) 2816 (current-buffer))
2790 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
2791 ;; Read output. 2817 ;; Read output.
2792 (with-timeout (10 (ert-fail "`async-shell-command' timed out")) 2818 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
2793 (while (< (- (point-max) (point-min)) 2819 (while (< (- (point-max) (point-min))
@@ -2816,7 +2842,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2816 (write-region "foo" nil tmp-name) 2842 (write-region "foo" nil tmp-name)
2817 (should (file-exists-p tmp-name)) 2843 (should (file-exists-p tmp-name))
2818 (async-shell-command "read line; ls $line" (current-buffer)) 2844 (async-shell-command "read line; ls $line" (current-buffer))
2819 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
2820 (process-send-string 2845 (process-send-string
2821 (get-buffer-process (current-buffer)) 2846 (get-buffer-process (current-buffer))
2822 (format "%s\n" (file-name-nondirectory tmp-name))) 2847 (format "%s\n" (file-name-nondirectory tmp-name)))
@@ -2847,8 +2872,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2847 "Like `shell-command-to-string', but for asynchronous processes." 2872 "Like `shell-command-to-string', but for asynchronous processes."
2848 (with-temp-buffer 2873 (with-temp-buffer
2849 (async-shell-command command (current-buffer)) 2874 (async-shell-command command (current-buffer))
2850 ;; Suppress nasty messages.
2851 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
2852 (with-timeout (10) 2875 (with-timeout (10)
2853 (while (get-buffer-process (current-buffer)) 2876 (while (get-buffer-process (current-buffer))
2854 (accept-process-output (get-buffer-process (current-buffer)) 0.1))) 2877 (accept-process-output (get-buffer-process (current-buffer)) 0.1)))
@@ -3046,11 +3069,13 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
3046 ;; We must force a reconnect, in order to activate $BZR_HOME. 3069 ;; We must force a reconnect, in order to activate $BZR_HOME.
3047 (tramp-cleanup-connection 3070 (tramp-cleanup-connection
3048 (tramp-dissect-file-name tramp-test-temporary-file-directory) 3071 (tramp-dissect-file-name tramp-test-temporary-file-directory)
3049 nil 'keep-password) 3072 'keep-debug 'keep-password)
3050 '(Bzr)) 3073 '(Bzr))
3051 (t nil))))) 3074 (t nil))))
3075 ;; Suppress nasty messages.
3076 (inhibit-message t))
3052 (skip-unless vc-handled-backends) 3077 (skip-unless vc-handled-backends)
3053 (message "%s" vc-handled-backends) 3078 (unless quoted (tramp--test-message "%s" vc-handled-backends))
3054 3079
3055 (unwind-protect 3080 (unwind-protect
3056 (progn 3081 (progn
@@ -3656,90 +3681,114 @@ Use the `ls' command."
3656 "Check parallel asynchronous requests. 3681 "Check parallel asynchronous requests.
3657Such requests could arrive from timers, process filters and 3682Such requests could arrive from timers, process filters and
3658process sentinels. They shall not disturb each other." 3683process sentinels. They shall not disturb each other."
3659 ;; Mark as failed until bug has been fixed.
3660 :expected-result :failed
3661 :tags '(:expensive-test) 3684 :tags '(:expensive-test)
3662 (skip-unless (tramp--test-enabled)) 3685 (skip-unless (tramp--test-enabled))
3663 (skip-unless (tramp--test-sh-p)) 3686 (skip-unless (tramp--test-sh-p))
3664 3687
3665 (dolist (quoted (if tramp--test-expensive-test '(nil t) '(nil))) 3688 (let* ((tmp-name (tramp--test-make-temp-name))
3666 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. 3689 (default-directory tmp-name)
3667 ;; This has the side effect, that this test fails instead to 3690 ;; Do not cache Tramp properties.
3668 ;; abort. Good for hydra. 3691 (remote-file-name-inhibit-cache t)
3669 (tramp--instrument-test-case 0 3692 (process-file-side-effects t)
3670 (let* ((tmp-name (tramp--test-make-temp-name nil quoted)) 3693 ;; Suppress nasty messages.
3671 (default-directory tmp-name) 3694 (inhibit-message t)
3672 (remote-file-name-inhibit-cache t) 3695 (number-proc 10)
3673 timer buffers kill-buffer-query-functions) 3696 (timer-repeat 1)
3697 ;; We must distinguish due to performance reasons.
3698 (timer-operation
3699 (cond
3700 ((string-equal "mock" (file-remote-p tmp-name 'method))
3701 'vc-registered)
3702 (t 'file-attributes)))
3703 timer buffers kill-buffer-query-functions)
3674 3704
3675 (unwind-protect 3705 (unwind-protect
3676 (progn 3706 (progn
3677 (make-directory tmp-name) 3707 (make-directory tmp-name)
3678 3708
3679 ;; Setup a timer in order to raise an ordinary command 3709 ;; Setup a timer in order to raise an ordinary command again
3680 ;; again and again. `vc-registered' is well suited, 3710 ;; and again. `vc-registered' is well suited, because there
3681 ;; because there are many checks. 3711 ;; are many checks.
3682 (setq 3712 (setq
3683 timer 3713 timer
3684 (run-at-time 3714 (run-at-time
3685 0 1 3715 0 timer-repeat
3686 (lambda () 3716 (lambda ()
3687 (when buffers 3717 (when buffers
3688 (vc-registered 3718 (let ((file
3689 (buffer-name (nth (random (length buffers)) buffers))))))) 3719 (buffer-name (nth (random (length buffers)) buffers))))
3690 3720 (funcall timer-operation file))))))
3691 ;; Create temporary buffers. The number of buffers 3721
3692 ;; corresponds to the number of processes; it could be 3722 ;; Create temporary buffers. The number of buffers
3693 ;; increased in order to make pressure on Tramp. 3723 ;; corresponds to the number of processes; it could be
3694 (dotimes (_i 5) 3724 ;; increased in order to make pressure on Tramp.
3695 (add-to-list 'buffers (generate-new-buffer "*temp*"))) 3725 (dotimes (_i number-proc)
3696 3726 (add-to-list 'buffers (generate-new-buffer "foo")))
3697 ;; Open asynchronous processes. Set process sentinel. 3727
3698 (dolist (buf buffers) 3728 ;; Open asynchronous processes. Set process sentinel.
3699 (async-shell-command "read line; touch $line; echo $line" buf) 3729 (dolist (buf buffers)
3730 (let ((proc
3731 (start-file-process-shell-command
3732 (buffer-name buf) buf
3733 (concat
3734 "(read line && echo $line >$line);"
3735 "(read line && cat $line);"
3736 "(read line && rm $line)")))
3737 (file (expand-file-name (buffer-name buf))))
3738 ;; Remember the file name. Add counter.
3739 (process-put proc 'foo file)
3740 (process-put proc 'bar 0)
3741 ;; Add process filter.
3742 (set-process-filter
3743 proc
3744 (lambda (proc string)
3745 (with-current-buffer (process-buffer proc)
3746 (insert string))
3747 (unless (zerop (length string))
3748 (should (file-attributes (process-get proc 'foo))))))
3749 ;; Add process sentinel.
3700 (set-process-sentinel 3750 (set-process-sentinel
3701 (get-buffer-process buf) 3751 proc
3702 (lambda (proc _state) 3752 (lambda (proc _state)
3703 (delete-file (buffer-name (process-buffer proc)))))) 3753 (should-not (file-attributes (process-get proc 'foo)))))))
3704 3754
3705 ;; Send a string. Use a random order of the buffers. Mix 3755 ;; Send a string. Use a random order of the buffers. Mix
3706 ;; with regular operation. 3756 ;; with regular operation.
3707 (let ((buffers (copy-sequence buffers)) 3757 (let ((buffers (copy-sequence buffers)))
3708 buf) 3758 (while buffers
3709 (while buffers 3759 (let* ((buf (nth (random (length buffers)) buffers))
3710 (setq buf (nth (random (length buffers)) buffers)) 3760 (proc (get-buffer-process buf))
3711 (process-send-string 3761 (file (process-get proc 'foo))
3712 (get-buffer-process buf) (format "'%s'\n" buf)) 3762 (count (process-get proc 'bar)))
3713 (file-attributes (buffer-name buf)) 3763 ;; Regular operation.
3714 (setq buffers (delq buf buffers)))) 3764 (if (= count 0)
3715 3765 (should-not (file-attributes file))
3716 ;; Wait until the whole output has been read. 3766 (should (file-attributes file)))
3717 (with-timeout ((* 10 (length buffers)) 3767 ;; Send string to process.
3718 (ert-fail "`async-shell-command' timed out")) 3768 (process-send-string proc (format "%s\n" (buffer-name buf)))
3719 (let ((buffers (copy-sequence buffers)) 3769 (accept-process-output proc 0.1 nil 0)
3720 buf) 3770 ;; Regular operation.
3721 (while buffers 3771 (if (= count 2)
3722 (setq buf (nth (random (length buffers)) buffers)) 3772 (should-not (file-attributes file))
3723 (if (ignore-errors 3773 (should (file-attributes file)))
3724 (memq (process-status (get-buffer-process buf)) 3774 (process-put proc 'bar (1+ count))
3725 '(run open))) 3775 (unless (process-live-p proc)
3726 (accept-process-output (get-buffer-process buf) 0.1) 3776 (setq buffers (delq buf buffers))))))
3727 (setq buffers (delq buf buffers)))))) 3777
3728 3778 ;; Checks. All process output shall exists in the
3729 ;; Check. 3779 ;; respective buffers. All created files shall be deleted.
3730 (dolist (buf buffers) 3780 (dolist (buf buffers)
3731 (with-current-buffer buf 3781 (with-current-buffer buf
3732 (should 3782 (should (string-equal (format "%s\n" buf) (buffer-string)))))
3733 (string-equal (format "'%s'\n" buf) (buffer-string))))) 3783 (should-not
3734 (should-not 3784 (directory-files tmp-name nil directory-files-no-dot-files-regexp)))
3735 (directory-files 3785
3736 tmp-name nil directory-files-no-dot-files-regexp))) 3786 ;; Cleanup.
3737 3787 (dolist (buf buffers)
3738 ;; Cleanup. 3788 (ignore-errors (delete-process (get-buffer-process buf)))
3739 (ignore-errors (cancel-timer timer)) 3789 (ignore-errors (kill-buffer buf)))
3740 (ignore-errors (delete-directory tmp-name 'recursive)) 3790 (ignore-errors (cancel-timer timer))
3741 (dolist (buf buffers) 3791 (ignore-errors (delete-directory tmp-name 'recursive)))))
3742 (ignore-errors (kill-buffer buf))))))))
3743 3792
3744(ert-deftest tramp-test37-recursive-load () 3793(ert-deftest tramp-test37-recursive-load ()
3745 "Check that Tramp does not fail due to recursive load." 3794 "Check that Tramp does not fail due to recursive load."
@@ -3836,8 +3885,8 @@ Since it unloads Tramp, it shall be the last test to run."
3836;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?). 3885;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
3837;; * Fix Bug#27009. Set expected error of 3886;; * Fix Bug#27009. Set expected error of
3838;; `tramp-test29-environment-variables-and-port-numbers'. 3887;; `tramp-test29-environment-variables-and-port-numbers'.
3839;; * Fix Bug#16928. Set expected error of `tramp-test36-asynchronous-requests'. 3888;; * Fix Bug#16928 in `tramp-test36-asynchronous-requests'.
3840;; * Fix `tramp-test38-unload' (Not all symbols are unbound). Set 3889;; * Fix `tramp-test39-unload' (Not all symbols are unbound). Set
3841;; expected error. 3890;; expected error.
3842 3891
3843(defun tramp-test-all (&optional interactive) 3892(defun tramp-test-all (&optional interactive)