]> git.eshelyaron.com Git - emacs.git/commitdiff
Extend `file-notify-test02-rm-watch'
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 22 Mar 2017 13:15:45 +0000 (14:15 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Wed, 22 Mar 2017 13:15:45 +0000 (14:15 +0100)
* test/lisp/filenotify-tests.el (file-notify-test02-rm-watch):
Expect it failed for inotify.  Divide tests into different
`unwind-protect' clauses.  Check, that removing watch
descriptors out of order do not harm.  (Bug#26126)

test/lisp/filenotify-tests.el

index 720803223791fb2984a0a749daae1c222b712b66..654e1af1123cbf3762d293476e8278fad7229364 100644 (file)
@@ -340,20 +340,24 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
   (expand-file-name
    (make-temp-name "file-notify-test") temporary-file-directory))
 
-;; This test is inspired by Bug#26127.
+;; This test is inspired by Bug#26126 and Bug#26127.
 (ert-deftest file-notify-test02-rm-watch ()
   "Check `file-notify-rm-watch'."
+  ;; There is a problem with inotify removing watch descriptors out of
+  ;; order.  Temporarily, we expect to fail this test until it is
+  ;; fixed.
+  :expected-result
+    (if (string-equal (file-notify--test-library) "inotify") :failed :passed)
   (skip-unless (file-notify--test-local-enabled))
 
   (unwind-protect
+      ;; Check, that `file-notify-rm-watch' works.
       (progn
-        ;; Check, that `file-notify-rm-watch' works.
         (should
          (setq file-notify--test-desc
                (file-notify-add-watch
                 temporary-file-directory '(change) #'ignore)))
         (file-notify-rm-watch file-notify--test-desc)
-
         ;; Check, that any parameter is accepted.
         (condition-case err
             (progn
@@ -363,7 +367,15 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
               (file-notify-rm-watch 'foo))
           (error (ert-fail err)))
 
-        ;; Check, that no error is returned removing a watch descriptor twice.
+        ;; The environment shall be cleaned up.
+        (file-notify--test-cleanup-p))
+
+    ;; Cleanup.
+    (file-notify--test-cleanup))
+
+  (unwind-protect
+      ;; Check, that no error is returned removing a watch descriptor twice.
+      (progn
         (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
               file-notify--test-tmpfile1 (file-notify--test-make-temp-name))
         (should
@@ -374,6 +386,7 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
          (setq file-notify--test-desc1
                (file-notify-add-watch
                 file-notify--test-tmpfile1 '(change) #'ignore)))
+        ;; Remove `file-notify--test-desc' twice.
         (file-notify-rm-watch file-notify--test-desc)
         (file-notify-rm-watch file-notify--test-desc)
         (file-notify-rm-watch file-notify--test-desc1)
@@ -381,6 +394,40 @@ This returns only for the local case and gfilenotify; otherwise it is nil.
         ;; The environment shall be cleaned up.
         (file-notify--test-cleanup-p))
 
+    ;; Cleanup.
+    (file-notify--test-cleanup))
+
+  (unwind-protect
+      ;; Check, that removing watch descriptors out of order do not harm.
+      (let (results)
+        (cl-flet ((first-callback (event)
+                   (when (eq (nth 1 event) 'deleted) (push 1 results)))
+                  (second-callback (event)
+                   (when (eq (nth 1 event) 'deleted) (push 2 results))))
+          (setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
+          (write-region
+           "any text" nil file-notify--test-tmpfile nil 'no-message)
+          (should
+           (setq file-notify--test-desc
+                 (file-notify-add-watch
+                  file-notify--test-tmpfile
+                  '(change) #'first-callback)))
+          (should
+           (setq file-notify--test-desc1
+                 (file-notify-add-watch
+                  file-notify--test-tmpfile
+                  '(change) #'second-callback)))
+          ;; Remove first watch.
+          (file-notify-rm-watch file-notify--test-desc)
+          ;; Only the second callback shall run.
+          (delete-file file-notify--test-tmpfile)
+          (file-notify--wait-for-events
+           (file-notify--test-timeout) results)
+          (should (equal results (list 2)))
+
+          ;; The environment shall be cleaned up.
+          (file-notify--test-cleanup-p)))
+
     ;; Cleanup.
     (file-notify--test-cleanup)))