Fix Bug#21669

* lisp/filenotify.el (file-notify-rm-watch): Improve check for
calling low-level functions.

* test/automated/file-notify-tests.el (file-notify--test-timeout):
Decrase to 6 seconds for remote directories.
(file-notify-test02-events): Expect different number of
`attribute-changed' events for the local and remote cases.  Apply
short delays between the operations, in order to receive all
events in the remote case.  Combine `attribute-change' tests.
(Bug#21669)
This commit is contained in:
Michael Albinus 2015-10-23 13:14:09 +02:00
parent 0f7334147d
commit 71d6acff1c
2 changed files with 31 additions and 26 deletions

View file

@ -333,7 +333,9 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
(when (stringp dir)
;; Call low-level function.
(when (null (cdr registered))
(when (or (not file)
(and (= (length (cdr registered)) 1)
(assoc file (cdr registered))))
(condition-case nil
(if handler
;; A file name handler could exist even if there is no local

View file

@ -63,7 +63,7 @@
(defvar file-notify--test-events nil)
(defun file-notify--test-timeout ()
"Timeout to wait for arriving events, in seconds."
(if (file-remote-p temporary-file-directory) 10 3))
(if (file-remote-p temporary-file-directory) 6 3))
(defun file-notify--test-cleanup ()
"Cleanup after a test."
@ -325,38 +325,41 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered."
file-notify--test-tmpfile
'(attribute-change) 'file-notify--test-event-handler))
(file-notify--test-with-events
(file-notify--test-timeout) '(attribute-changed)
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
(set-file-modes file-notify--test-tmpfile 000)
(delete-file file-notify--test-tmpfile))
(file-notify-rm-watch file-notify--test-desc)
;; With gfilenotify, there are timing issues with attribute
;; changes in a short time period. So we apply 2 tests.
(setq file-notify--test-desc
(file-notify-add-watch
file-notify--test-tmpfile
'(attribute-change) 'file-notify--test-event-handler))
(file-notify--test-with-events
(file-notify--test-timeout) '(attribute-changed)
(file-notify--test-timeout)
(if (file-remote-p temporary-file-directory)
;; In the remote case, `write-region' raises also an
;; `attribute-changed' event.
'(attribute-changed attribute-changed attribute-changed)
'(attribute-changed attribute-changed))
;; We must use short delays between the operations.
;; Otherwise, not all events arrive us in the remote case.
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
(sleep-for 0.1)
(set-file-modes file-notify--test-tmpfile 000)
(sleep-for 0.1)
(set-file-times file-notify--test-tmpfile '(0 0))
(sleep-for 0.1)
(delete-file file-notify--test-tmpfile))
(file-notify-rm-watch file-notify--test-desc))
;; Check the global sequence again just to make sure that
;; `file-notify--test-events' has been set correctly.
(should (equal (mapcar #'cadr file-notify--test-events)
(if (eq file-notify--library 'w32notify)
'(created changed deleted
created changed changed deleted
created changed renamed)
'(created changed deleted
created changed deleted
created changed renamed
attribute-changed attribute-changed))))
(should (equal
(mapcar #'cadr file-notify--test-events)
(if (eq file-notify--library 'w32notify)
'(created changed deleted
created changed changed deleted
created changed renamed)
(if (file-remote-p temporary-file-directory)
'(created changed deleted
created changed deleted
created changed renamed
attribute-changed attribute-changed attribute-changed)
'(created changed deleted
created changed deleted
created changed renamed
attribute-changed attribute-changed)))))
(should file-notify--test-results)
(dolist (result file-notify--test-results)
;;(message "%s" (ert-test-result-messages result))