Improve file-notify-test08-watched-file-in-watched-dir

* test/automated/file-notify-tests.el (file-notify--test-desc2):
New variable.
(file-notify--test-cleanup): Use it.
(file-notify--test-event-handler): Enable trace.
(file-notify-test08-watched-file-in-watched-dir): Tag it as
:expensive-test.  Rewrite callbacks to use
`file-notify--test-event-handler'.  Read events in loop.  Check
`file-notify--test-results'.
(file-notify-test08-watched-file-in-watched-dir): Fix docstring.
This commit is contained in:
Michael Albinus 2016-02-20 14:04:36 +01:00
parent 1cb126866d
commit 5d17ae7d46

View file

@ -59,6 +59,7 @@
(defvar file-notify--test-tmpfile1 nil) (defvar file-notify--test-tmpfile1 nil)
(defvar file-notify--test-desc nil) (defvar file-notify--test-desc nil)
(defvar file-notify--test-desc1 nil) (defvar file-notify--test-desc1 nil)
(defvar file-notify--test-desc2 nil)
(defvar file-notify--test-results nil) (defvar file-notify--test-results nil)
(defvar file-notify--test-event nil) (defvar file-notify--test-event nil)
(defvar file-notify--test-events nil) (defvar file-notify--test-events nil)
@ -79,6 +80,7 @@ It is different for local and remote file notification libraries.")
"Cleanup after a test." "Cleanup after a test."
(file-notify-rm-watch file-notify--test-desc) (file-notify-rm-watch file-notify--test-desc)
(file-notify-rm-watch file-notify--test-desc1) (file-notify-rm-watch file-notify--test-desc1)
(file-notify-rm-watch file-notify--test-desc2)
(ignore-errors (ignore-errors
(delete-file (file-newest-backup file-notify--test-tmpfile))) (delete-file (file-newest-backup file-notify--test-tmpfile)))
@ -99,6 +101,7 @@ It is different for local and remote file notification libraries.")
file-notify--test-tmpfile1 nil file-notify--test-tmpfile1 nil
file-notify--test-desc nil file-notify--test-desc nil
file-notify--test-desc1 nil file-notify--test-desc1 nil
file-notify--test-desc2 nil
file-notify--test-results nil file-notify--test-results nil
file-notify--test-events nil) file-notify--test-events nil)
(when file-notify--test-event (when file-notify--test-event
@ -278,7 +281,7 @@ and the event to `file-notify--test-events'."
(unless (string-match (unless (string-match
(regexp-quote ".#") (regexp-quote ".#")
(file-notify--event-file-name file-notify--test-event)) (file-notify--event-file-name file-notify--test-event))
;;(message "file-notify--test-event-handler %S" file-notify--test-event) (message "file-notify--test-event-handler %S" file-notify--test-event)
(setq file-notify--test-events (setq file-notify--test-events
(append file-notify--test-events `(,file-notify--test-event)) (append file-notify--test-events `(,file-notify--test-event))
file-notify--test-results file-notify--test-results
@ -552,8 +555,8 @@ longer than timeout seconds for the events to be delivered."
(let (file-notify--test-events) (let (file-notify--test-events)
(file-notify-rm-watch file-notify--test-desc))) (file-notify-rm-watch file-notify--test-desc)))
;; Check the global sequence again just to make sure that ;; Check the global sequence just to make sure that all
;; `file-notify--test-events' has been set correctly. ;; results are as expected.
(should file-notify--test-results) (should file-notify--test-results)
(dolist (result file-notify--test-results) (dolist (result file-notify--test-results)
(when (ert-test-failed-p result) (when (ert-test-failed-p result)
@ -948,6 +951,7 @@ descriptors that were issued when registering the watches. This
test caters for the situation in bug#22736 where the callback for test caters for the situation in bug#22736 where the callback for
the directory received events for the file with the descriptor of the directory received events for the file with the descriptor of
the file watch." the file watch."
:tags '(:expensive-test)
(skip-unless (file-notify--test-local-enabled)) (skip-unless (file-notify--test-local-enabled))
(unwind-protect (unwind-protect
@ -957,42 +961,52 @@ the file watch."
(setq file-notify--test-tmpfile1 (setq file-notify--test-tmpfile1
(let ((temporary-file-directory file-notify--test-tmpfile)) (let ((temporary-file-directory file-notify--test-tmpfile))
(make-temp-file "file"))) (make-temp-file "file")))
(cl-flet ((dir-callback (cl-flet ((dir-callback (event)
(ev) (message "dir-callback %s" event)
(should (equal file-notify--test-desc (car ev)))) (let ((file-notify--test-desc file-notify--test-desc1))
(file-callback (file-notify--test-event-handler event)))
(ev) (file-callback (event)
(should (equal file-notify--test-desc1 (car ev))))) (message "file-callback %s" event)
(let ((file-notify--test-desc file-notify--test-desc2))
(file-notify--test-event-handler event))))
(should (should
(setq file-notify--test-desc (setq file-notify--test-desc1
(file-notify-add-watch (file-notify-add-watch
file-notify--test-tmpfile file-notify--test-tmpfile
'(change attribute-change) #'dir-callback))) '(change attribute-change) #'dir-callback)))
(should (should
(setq file-notify--test-desc1 (setq file-notify--test-desc2
(file-notify-add-watch (file-notify-add-watch
file-notify--test-tmpfile1 file-notify--test-tmpfile1
'(change attribute-change) #'file-callback))) '(change attribute-change) #'file-callback)))
(should (file-notify-valid-p file-notify--test-desc))
(should (file-notify-valid-p file-notify--test-desc1)) (should (file-notify-valid-p file-notify--test-desc1))
(should (file-notify-valid-p file-notify--test-desc2))
(dotimes (i 100) (dotimes (i 100)
(read-event nil nil file-notify--test-read-event-timeout)
(if (< 0 (random)) (if (< 0 (random))
(write-region (write-region
"any text" nil file-notify--test-tmpfile1 t 'no-message) "any text" nil file-notify--test-tmpfile1 t 'no-message)
(let ((temporary-file-directory file-notify--test-tmpfile)) (let ((temporary-file-directory file-notify--test-tmpfile))
(make-temp-file "fileX"))))) (make-temp-file "fileX"))))
;; After saving the buffer, the descriptor is still valid. ;; After saving the buffer, the descriptor is still valid.
(should (file-notify-valid-p file-notify--test-desc)) (should (file-notify-valid-p file-notify--test-desc1))
(should (file-notify-valid-p file-notify--test-desc1)) (should (file-notify-valid-p file-notify--test-desc2))
(delete-file file-notify--test-tmpfile1) (delete-file file-notify--test-tmpfile1)
(delete-directory file-notify--test-tmpfile)) (delete-directory file-notify--test-tmpfile 'recursive))
;; Check the global sequence just to make sure that all
;; results are as expected.
(should file-notify--test-results)
(dolist (result file-notify--test-results)
(when (ert-test-failed-p result)
(ert-fail
(cadr (ert-test-result-with-condition-condition result))))))
;; Cleanup. ;; Cleanup.
(file-notify--test-cleanup))) (file-notify--test-cleanup)))
(file-notify--deftest-remote file-notify-test08-watched-file-in-watched-dir (file-notify--deftest-remote file-notify-test08-watched-file-in-watched-dir
"Checks what `file-notify-test08-watched-file-in-watched-dir' "Check `file-notify-test08-watched-file-in-watched-dir' for remote files.")
checks, just for a remote directory and file.")
(defun file-notify-test-all (&optional interactive) (defun file-notify-test-all (&optional interactive)
"Run all tests for \\[file-notify]." "Run all tests for \\[file-notify]."