Skip to content

Commit 03b66d2

Browse files
committed
Make tramp-test43-asynchronous-requests working, again
* test/lisp/net/tramp-tests.el (tramp-list-tramp-buffers): Declare `tramp-list-tramp-buffers'. (tramp--test-ignore-make-symbolic-link-error) (tramp--test-ignore-add-name-to-file-error): Improve declaration. (tramp--test-with-proper-process-name-and-buffer): New macro. (tramp-test43-asynchronous-requests): Use the macro for timer, process filter and process sentinel. Comment the remote file operation in the timer. Remove further async events. Accept output from all processes.
1 parent fb39d31 commit 03b66d2

File tree

1 file changed

+77
-40
lines changed

1 file changed

+77
-40
lines changed

test/lisp/net/tramp-tests.el

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
(declare-function tramp-get-remote-path "tramp-sh")
5656
(declare-function tramp-get-remote-perl "tramp-sh")
5757
(declare-function tramp-get-remote-stat "tramp-sh")
58+
(declare-function tramp-list-tramp-buffers "tramp-cmds")
5859
(declare-function tramp-method-out-of-band-p "tramp-sh")
5960
(declare-function tramp-smb-get-localname "tramp-smb")
6061
(defvar auto-save-file-name-transforms)
@@ -2962,7 +2963,7 @@ This tests also `file-directory-p' and `file-accessible-directory-p'."
29622963
;; support symbolic links at all.
29632964
(defmacro tramp--test-ignore-make-symbolic-link-error (&rest body)
29642965
"Run BODY, ignoring \"make-symbolic-link not supported\" file error."
2965-
(declare (indent defun) (debug t))
2966+
(declare (indent defun) (debug (body)))
29662967
`(condition-case err
29672968
(progn ,@body)
29682969
((error quit debug)
@@ -3175,7 +3176,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
31753176
;; Method "smb" could run into "NT_STATUS_REVISION_MISMATCH" error.
31763177
(defmacro tramp--test-ignore-add-name-to-file-error (&rest body)
31773178
"Run BODY, ignoring \"error with add-name-to-file\" file error."
3178-
(declare (indent defun) (debug t))
3179+
(declare (indent defun) (debug (body)))
31793180
`(condition-case err
31803181
(progn ,@body)
31813182
((error quit debug)
@@ -5483,6 +5484,37 @@ Use the `ls' command."
54835484
(defconst tramp--test-asynchronous-requests-timeout 300
54845485
"Timeout for `tramp-test43-asynchronous-requests'.")
54855486

5487+
(defmacro tramp--test-with-proper-process-name-and-buffer (proc &rest body)
5488+
"Set \"process-name\" and \"process-buffer\" connection properties.
5489+
This is needed in timer functions as well as process filters and sentinels."
5490+
(declare (indent 1) (debug (processp body)))
5491+
`(let* ((v (tramp-get-connection-property ,proc "vector" nil))
5492+
(pname (tramp-get-connection-property v "process-name" nil))
5493+
(pbuffer (tramp-get-connection-property v "process-buffer" nil)))
5494+
(tramp--test-message
5495+
"tramp--test-with-proper-process-name-and-buffer before %s %s"
5496+
(tramp-get-connection-property v "process-name" nil)
5497+
(tramp-get-connection-property v "process-buffer" nil))
5498+
(if (process-name ,proc)
5499+
(tramp-set-connection-property v "process-name" (process-name ,proc))
5500+
(tramp-flush-connection-property v "process-name"))
5501+
(if (process-buffer ,proc)
5502+
(tramp-set-connection-property
5503+
v "process-buffer" (process-buffer ,proc))
5504+
(tramp-flush-connection-property v "process-buffer"))
5505+
(tramp--test-message
5506+
"tramp--test-with-proper-process-name-and-buffer changed %s %s"
5507+
(tramp-get-connection-property v "process-name" nil)
5508+
(tramp-get-connection-property v "process-buffer" nil))
5509+
(unwind-protect
5510+
(progn ,@body)
5511+
(if pname
5512+
(tramp-set-connection-property v "process-name" pname)
5513+
(tramp-flush-connection-property v "process-name"))
5514+
(if pbuffer
5515+
(tramp-set-connection-property v "process-buffer" pbuffer)
5516+
(tramp-flush-connection-property v "process-buffer")))))
5517+
54865518
;; This test is inspired by Bug#16928.
54875519
(ert-deftest tramp-test43-asynchronous-requests ()
54885520
"Check parallel asynchronous requests.
@@ -5532,10 +5564,10 @@ process sentinels. They shall not disturb each other."
55325564
((getenv "EMACS_HYDRA_CI") 10)
55335565
(t 1)))
55345566
;; We must distinguish due to performance reasons.
5535-
(timer-operation
5536-
(cond
5537-
((tramp--test-mock-p) #'vc-registered)
5538-
(t #'file-attributes)))
5567+
;; (timer-operation
5568+
;; (cond
5569+
;; ((tramp--test-mock-p) #'vc-registered)
5570+
;; (t #'file-attributes)))
55395571
;; This is when all timers start. We check inside the
55405572
;; timer function, that we don't exceed timeout.
55415573
(timer-start (current-time))
@@ -5553,25 +5585,31 @@ process sentinels. They shall not disturb each other."
55535585
(run-at-time
55545586
0 timer-repeat
55555587
(lambda ()
5556-
(when (> (- (time-to-seconds) (time-to-seconds timer-start))
5557-
tramp--test-asynchronous-requests-timeout)
5558-
(tramp--test-timeout-handler))
5559-
(when buffers
5560-
(let ((time (float-time))
5561-
(default-directory tmp-name)
5562-
(file
5563-
(buffer-name (nth (random (length buffers)) buffers))))
5564-
(tramp--test-message
5565-
"Start timer %s %s" file (current-time-string))
5566-
(funcall timer-operation file)
5567-
;; Adjust timer if it takes too much time.
5568-
(tramp--test-message
5569-
"Stop timer %s %s" file (current-time-string))
5570-
(when (> (- (float-time) time) timer-repeat)
5571-
(setq timer-repeat (* 1.5 timer-repeat))
5572-
(setf (timer--repeat-delay timer) timer-repeat)
5588+
(tramp--test-with-proper-process-name-and-buffer
5589+
(get-buffer-process
5590+
(tramp-get-buffer
5591+
(tramp-dissect-file-name
5592+
tramp-test-temporary-file-directory)))
5593+
(when (> (- (time-to-seconds) (time-to-seconds timer-start))
5594+
tramp--test-asynchronous-requests-timeout)
5595+
(tramp--test-timeout-handler))
5596+
(when buffers
5597+
(let ((time (float-time))
5598+
(default-directory tmp-name)
5599+
(file
5600+
(buffer-name
5601+
(nth (random (length buffers)) buffers))))
5602+
(tramp--test-message
5603+
"Start timer %s %s" file (current-time-string))
5604+
;; (funcall timer-operation file)
55735605
(tramp--test-message
5574-
"Increase timer %s" timer-repeat)))))))
5606+
"Stop timer %s %s" file (current-time-string))
5607+
;; Adjust timer if it takes too much time.
5608+
(when (> (- (float-time) time) timer-repeat)
5609+
(setq timer-repeat (* 1.1 timer-repeat))
5610+
(setf (timer--repeat-delay timer) timer-repeat)
5611+
(tramp--test-message
5612+
"Increase timer %s" timer-repeat))))))))
55755613

55765614
;; Create temporary buffers. The number of buffers
55775615
;; corresponds to the number of processes; it could be
@@ -5598,27 +5636,28 @@ process sentinels. They shall not disturb each other."
55985636
(set-process-filter
55995637
proc
56005638
(lambda (proc string)
5601-
(tramp--test-message
5602-
"Process filter %s %s %s" proc string (current-time-string))
5603-
(with-current-buffer (process-buffer proc)
5604-
(insert string))
5605-
(when (< (process-get proc 'bar) 2)
5606-
(dired-uncache (process-get proc 'foo))
5607-
(should (file-attributes (process-get proc 'foo))))))
5639+
(tramp--test-with-proper-process-name-and-buffer proc
5640+
(tramp--test-message
5641+
"Process filter %s %s %s"
5642+
proc string (current-time-string))
5643+
(with-current-buffer (process-buffer proc)
5644+
(insert string))
5645+
(when (< (process-get proc 'bar) 2)
5646+
(dired-uncache (process-get proc 'foo))
5647+
(should (file-attributes (process-get proc 'foo)))))))
56085648
;; Add process sentinel. It shall not perform remote
56095649
;; operations, triggering Tramp processes. This blocks.
56105650
(set-process-sentinel
56115651
proc
56125652
(lambda (proc _state)
5613-
(tramp--test-message
5614-
"Process sentinel %s %s" proc (current-time-string))))))
5653+
(tramp--test-with-proper-process-name-and-buffer proc
5654+
(tramp--test-message
5655+
"Process sentinel %s %s" proc (current-time-string)))))))
56155656

56165657
;; Send a string to the processes. Use a random order of
56175658
;; the buffers. Mix with regular operation.
56185659
(let ((buffers (copy-sequence buffers)))
56195660
(while buffers
5620-
;; Activate timer.
5621-
(sit-for 0.01 'nodisp)
56225661
(let* ((buf (nth (random (length buffers)) buffers))
56235662
(proc (get-buffer-process buf))
56245663
(file (process-get proc 'foo))
@@ -5632,9 +5671,7 @@ process sentinels. They shall not disturb each other."
56325671
(should (file-attributes file)))
56335672
;; Send string to process.
56345673
(process-send-string proc (format "%s\n" (buffer-name buf)))
5635-
(while (accept-process-output proc 0 nil 0))
5636-
;; Give the watchdog a chance.
5637-
(read-event nil nil 0.01)
5674+
(while (accept-process-output nil 0))
56385675
(tramp--test-message
56395676
"Continue action %d %s %s" count buf (current-time-string))
56405677
;; Regular operation post process action.
@@ -5864,8 +5901,8 @@ Since it unloads Tramp, it shall be the last test to run."
58645901
;; * Fix `tramp-test29-start-file-process' and
58655902
;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?).
58665903
;; * Implement `tramp-test31-interrupt-process' for `adb'.
5867-
;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. Looks
5868-
;; like it is resolved now. Remove `:unstable' tag?
5904+
;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. A remote
5905+
;; file name operation cannot run in the timer. Remove `:unstable' tag?
58695906

58705907
(provide 'tramp-tests)
58715908
;;; tramp-tests.el ends here

0 commit comments

Comments
 (0)