(defvar file-notify--test-event nil)
(defvar file-notify--test-events nil)
-(defconst file-notify--test-read-event-timeout
- (cond
- ;; Some events take several seconds to arrive on cygwin.
- ((eq system-type 'cygwin) 7)
- (t 0.01))
- "Timeout for `read-event' calls.
-It is different for local and remote file notification libraries.")
+(defun file-notify--test-read-event ()
+ "Read one event.
+There are different timeouts for local and remote file notification libraries."
+ (read-event
+ nil nil
+ (cond
+ ;; gio/gpollfilemonitor.c declares POLL_TIME_SECS 5. So we must
+ ;; wait at least this time.
+ ((and (string-equal (file-notify--test-library) "gfilenotify")
+ (string-equal (file-notify--test-monitor) "GPollFileMonitor"))
+ 7)
+ ((file-remote-p temporary-file-directory) 0.1)
+ (t 0.01))))
(defun file-notify--test-timeout ()
- "Timeout to wait for arriving events, in seconds."
+ "Timeout to wait for arriving a bunch of events, in seconds."
(cond
((file-remote-p temporary-file-directory) 6)
((string-equal (file-notify--test-library) "w32notify") 4)
TIMEOUT is the maximum time to wait for, in seconds."
`(with-timeout (,timeout (ignore))
(while (null ,until)
- (read-event nil nil file-notify--test-read-event-timeout))))
+ (file-notify--test-read-event))))
(defun file-notify--test-no-descriptors ()
"Check that `file-notify-descriptors' is an empty hash table.
"<[[:digit:]]+>\\'" ""
(process-name (cdr file-notify--test-remote-enabled-checked))))))
+(defun file-notify--test-monitor ()
+ "The used monitor for the test, as a string.
+This returns only for the local case and gfilenotify; otherwise it is nil.
+`file-notify--test-desc' must be a valid watch descriptor."
+ (and file-notify--test-desc
+ (null (file-remote-p temporary-file-directory))
+ (functionp 'gfile-monitor-name)
+ (gfile-monitor-name file-notify--test-desc)))
+
(defmacro file-notify--deftest-remote (test docstring)
"Define ert `TEST-remote' for remote files."
(declare (indent 1))
:tags '(:expensive-test)
(let* ((temporary-file-directory
file-notify-test-remote-temporary-file-directory)
- (file-notify--test-read-event-timeout 0.1)
(ert-test (ert-get-test ',test)))
(skip-unless (file-notify--test-remote-enabled))
(tramp-cleanup-connection
(setq file-notify--test-desc
(file-notify-add-watch
temporary-file-directory '(change) #'ignore)))
+ (when (file-notify--test-monitor)
+ (message "Monitor: `%s'" (file-notify--test-monitor)))
(file-notify-rm-watch file-notify--test-desc)
;; The environment shall be cleaned up.
events)))
create-lockfiles)
;; Flush pending events.
+ (file-notify--test-read-event)
(file-notify--wait-for-events
(file-notify--test-timeout)
(not (input-pending-p)))
(setq file-notify--test-events nil
file-notify--test-results nil)
- ;; cygwin needs a delay between setting a watch and beginning
- ;; file activity, or else the first event is not sent.
- (if (eq system-type 'cygwin)
- (sleep-for 1))
,@body
(file-notify--wait-for-events
;; More events need more time. Use some fudge factor.
(t '(created changed deleted stopped)))
(write-region
"another text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-file file-notify--test-tmpfile))
(file-notify-rm-watch file-notify--test-desc))
(changed changed deleted stopped))
(write-region
"another text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-file file-notify--test-tmpfile))
(file-notify-rm-watch file-notify--test-desc)
(t '(created changed deleted deleted stopped)))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-directory temporary-file-directory 'recursive))
(file-notify-rm-watch file-notify--test-desc))
deleted deleted deleted stopped)))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(copy-file file-notify--test-tmpfile file-notify--test-tmpfile1)
;; The next two events shall not be visible.
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(set-file-modes file-notify--test-tmpfile 000)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(set-file-times file-notify--test-tmpfile '(0 0))
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-directory temporary-file-directory 'recursive))
(file-notify-rm-watch file-notify--test-desc))
(t '(created changed renamed deleted deleted stopped)))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(rename-file file-notify--test-tmpfile file-notify--test-tmpfile1)
;; After the rename, we won't get events anymore.
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-directory temporary-file-directory 'recursive))
(file-notify-rm-watch file-notify--test-desc))
;; Check attribute change. Does not work for cygwin.
- (unless (eq system-type 'cygwin)
+ (unless (and (eq system-type 'cygwin)
+ (not (file-remote-p temporary-file-directory)))
(setq file-notify--test-tmpfile (file-notify--test-make-temp-name))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
(t '(attribute-changed attribute-changed)))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(set-file-modes file-notify--test-tmpfile 000)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(set-file-times file-notify--test-tmpfile '(0 0))
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-file file-notify--test-tmpfile))
(file-notify-rm-watch file-notify--test-desc))
(changed changed deleted stopped))
(write-region
"another text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-file file-notify--test-tmpfile))
;; After deleting the file, the descriptor is not valid anymore.
(should-not (file-notify-valid-p file-notify--test-desc))
(t '(created changed deleted deleted stopped)))
(write-region
"any text" nil file-notify--test-tmpfile nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(delete-directory temporary-file-directory t))
;; After deleting the parent directory, the descriptor must
;; not be valid anymore.
(let ((source-file-list source-file-list)
(target-file-list target-file-list))
(while (and source-file-list target-file-list)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(write-region "" nil (pop source-file-list) nil 'no-message)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(write-region "" nil (pop target-file-list) nil 'no-message))))
(file-notify--test-with-events
(cond
;; cygwin fires `changed' and `deleted' events, sometimes
;; in random order.
((eq system-type 'cygwin)
- (let ((r '(:random)))
- (dotimes (_i n r)
- (setq r (append r '(changed deleted))))))
+ (let (r)
+ (dotimes (_i n (cons :random r))
+ (setq r (append '(changed deleted) r)))))
(t (make-list n 'renamed)))
(let ((source-file-list source-file-list)
(target-file-list target-file-list))
(while (and source-file-list target-file-list)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(rename-file (pop source-file-list) (pop target-file-list) t))))
(file-notify--test-with-events (make-list n 'deleted)
(dolist (file target-file-list)
- (read-event nil nil file-notify--test-read-event-timeout)
- (delete-file file) file-notify--test-read-event-timeout))
+ (file-notify--test-read-event)
+ (delete-file file)))
(delete-directory file-notify--test-tmpfile)
;; The environment shall be cleaned up.
(file-notify--test-with-events
;; There could be one or two `changed' events.
(list
+ ;; cygwin.
+ (append
+ '(:random)
+ (make-list (/ n 2) 'changed)
+ (make-list (/ n 2) 'created)
+ (make-list (/ n 2) 'changed))
(append
'(:random)
;; Directory monitor and file monitor.
(make-list (/ n 2) 'created)
(make-list (/ n 2) 'changed)))
(dotimes (i n)
- (read-event nil nil file-notify--test-read-event-timeout)
+ (file-notify--test-read-event)
(if (zerop (mod i 2))
(write-region
"any text" nil file-notify--test-tmpfile1 t 'no-message)
;; Now we delete the directory.
(file-notify--test-with-events
(cond
- ;; In kqueue, just one `deleted' event for the directory
- ;; is received.
- ((string-equal (file-notify--test-library) "kqueue")
+ ;; In kqueue and for cygwin, just one `deleted' event for
+ ;; the directory is received.
+ ((or (eq system-type 'cygwin)
+ (string-equal (file-notify--test-library) "kqueue"))
'(deleted stopped))
(t (append
;; The directory monitor raises a `deleted' event for