summaryrefslogtreecommitdiff
path: root/test/lisp/filenotify-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/filenotify-tests.el')
-rw-r--r--test/lisp/filenotify-tests.el86
1 files changed, 76 insertions, 10 deletions
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index f16cc09b6f1..11af1f75574 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -939,10 +939,13 @@ delivered."
:tags '(:expensive-test)
(skip-unless (file-notify--test-local-enabled))
- ;; `auto-revert-buffers' runs every 5". And we must wait, until the
- ;; file has been reverted.
- (let ((timeout (if (file-remote-p temporary-file-directory) 60 10))
- buf)
+ ;; Run with shortened `auto-revert-interval' for a faster test.
+ (let* ((auto-revert-interval 1)
+ (timeout (if (file-remote-p temporary-file-directory)
+ 60 ; FIXME: can this be shortened?
+ (* auto-revert-interval 2.5)))
+ buf)
+ (auto-revert-set-timer)
(unwind-protect
(progn
;; In the remote case, `vc-refresh-state' returns undesired
@@ -960,10 +963,9 @@ delivered."
(sleep-for 1)
(auto-revert-mode 1)
- ;; `auto-revert-buffers' runs every 5".
(with-timeout (timeout (ignore))
(while (null auto-revert-notify-watch-descriptor)
- (sleep-for 1)))
+ (sleep-for 0.2)))
;; `file-notify--test-monitor' needs to know
;; `file-notify--test-desc' in order to compute proper
@@ -971,8 +973,7 @@ delivered."
(setq file-notify--test-desc auto-revert-notify-watch-descriptor)
;; GKqueueFileMonitor does not report the `changed' event.
- (skip-unless
- (not (eq (file-notify--test-monitor) 'GKqueueFileMonitor)))
+ (skip-when (eq (file-notify--test-monitor) 'GKqueueFileMonitor))
;; Check, that file notification has been used.
(should auto-revert-mode)
@@ -1032,7 +1033,7 @@ delivered."
(file-notify--test-cleanup))))
(file-notify--deftest-remote file-notify-test04-autorevert
- "Check autorevert via file notification for remote files.")
+ "Check autorevert via file notification for remote files." t)
(ert-deftest file-notify-test05-file-validity ()
"Check `file-notify-valid-p' for files."
@@ -1581,7 +1582,7 @@ the file watch."
:tags '(:expensive-test)
(skip-unless (file-notify--test-local-enabled))
;; This test does not work for kqueue (yet).
- (skip-unless (not (string-equal (file-notify--test-library) "kqueue")))
+ (skip-when (string-equal (file-notify--test-library) "kqueue"))
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
file-notify--test-tmpfile1 (file-notify--test-make-temp-name))
@@ -1706,6 +1707,71 @@ the file watch."
(file-notify--deftest-remote file-notify-test11-symlinks
"Check `file-notify-test11-symlinks' for remote files.")
+(ert-deftest file-notify-test12-unmount ()
+ "Check that file notification stop after unmounting the filesystem."
+ :tags '(:expensive-test)
+ (skip-unless (file-notify--test-local-enabled))
+ ;; This test does not work for w32notify.
+ (skip-when (string-equal (file-notify--test-library) "w32notify"))
+
+ (unwind-protect
+ (progn
+ (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
+ ;; File monitors like kqueue insist, that the watched file
+ ;; exists. Directory monitors are not bound to this
+ ;; restriction.
+ (when (string-equal (file-notify--test-library) "kqueue")
+ (write-region
+ "any text" nil file-notify--test-tmpfile nil 'no-message))
+
+ (should
+ (setq file-notify--test-desc
+ (file-notify--test-add-watch
+ file-notify--test-tmpfile
+ '(attribute-change change) #'file-notify--test-event-handler)))
+ (should (file-notify-valid-p file-notify--test-desc))
+
+ ;; Unmounting the filesystem should stop watching.
+ (file-notify--test-with-actions '(stopped)
+ ;; We emulate unmounting by calling
+ ;; `file-notify-handle-event' with a corresponding event.
+ (file-notify-handle-event
+ (make-file-notify
+ :-event
+ (list file-notify--test-desc
+ (pcase (file-notify--test-library)
+ ((or "inotify" "inotifywait") '(unmount isdir))
+ ((or "gfilenotify" "gio") '(unmounted))
+ ("kqueue" '(revoke))
+ (err (ert-fail (format "Library %s not supported" err))))
+ (pcase (file-notify--test-library)
+ ("kqueue" (file-local-name file-notify--test-tmpfile))
+ (_ (file-local-name file-notify--test-tmpdir)))
+ ;; In the inotify case, there is a 4th slot `cookie'.
+ ;; Since it is unused for `unmount', we ignore it.
+ )
+ :-callback
+ (pcase (file-notify--test-library)
+ ("inotify" #'file-notify--callback-inotify)
+ ("gfilenotify" #'file-notify--callback-gfilenotify)
+ ("kqueue" #'file-notify--callback-kqueue)
+ ((or "inotifywait" "gio") #'file-notify-callback)
+ (err (ert-fail (format "Library %s not supported" err)))))))
+
+ ;; The watch has been stopped.
+ (should-not (file-notify-valid-p file-notify--test-desc))
+
+ ;; The environment shall be cleaned up.
+ (when (string-equal (file-notify--test-library) "kqueue")
+ (delete-file file-notify--test-tmpfile))
+ (file-notify--test-cleanup-p))
+
+ ;; Cleanup.
+ (file-notify--test-cleanup)))
+
+(file-notify--deftest-remote file-notify-test12-unmount
+ "Check `file-notify-test12-unmount' for remote files.")
+
(defun file-notify-test-all (&optional interactive)
"Run all tests for \\[file-notify]."
(interactive "p")