diff options
| author | Michael Albinus | 2015-09-20 18:44:36 +0200 |
|---|---|---|
| committer | Michael Albinus | 2015-09-20 18:44:36 +0200 |
| commit | f5bdcb3221ba28326b47210773d84c49cc9b4a1e (patch) | |
| tree | f316feaf1d548b157ef1a3cfcbb831864e50c003 /test | |
| parent | ab11a1cf27ebe3791df45cccde3c851affd184dd (diff) | |
| download | emacs-f5bdcb3221ba28326b47210773d84c49cc9b4a1e.tar.gz emacs-f5bdcb3221ba28326b47210773d84c49cc9b4a1e.zip | |
Improve file notifications, especially for Tramp
* doc/lispref/files.texi (Magic File Names):
Mention `file-notify-valid-p'.
* doc/lispref/os.texi (File Notifications):
Describe `file-notify-valid-p'.
* etc/NEWS: Add `file-notify-valid-p'.
* lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-notify-add-watch):
Improve implementation.
(tramp-gvfs-monitor-file-process-filter): Rename from
`tramp-gvfs-file-gvfs-monitor-file-process-filter'. Delete
process if appropriate.
* lisp/net/tramp-sh.el (tramp-sh-handle-file-notify-add-watch):
Improve implementation.
(tramp-sh-gvfs-monitor-dir-process-filter): Rename from
`tramp-sh-file-gvfs-monitor-dir-process-filter'. Delete process
if appropriate.
(tramp-sh-inotifywait-process-filter): Rename from
`tramp-sh-file-inotifywait-process-filter'. Delete process if
appropriate.
* lisp/net/tramp.el (tramp-handle-file-notify-rm-watch):
Use `delete-process'
(tramp-handle-file-notify-valid-p): Check also, that file or
directory to be watched still exists.
* test/automated/file-notify-tests.el (file-notify--test-timeout):
New defun. Use it at all places a timeout is needed.
(file-notify--test-cleanup): Delete directories recursively.
Cleanup also Tramp connections.
(file-notify-test02-events): Add tests for `attribute-change'.
(file-notify-test04-file-validity, file-notify-test05-dir-validity):
Add tests for `file-notify-rm-watch'.
Diffstat (limited to 'test')
| -rw-r--r-- | test/automated/file-notify-tests.el | 140 |
1 files changed, 111 insertions, 29 deletions
diff --git a/test/automated/file-notify-tests.el b/test/automated/file-notify-tests.el index dfc32443d17..9d66f03ae0c 100644 --- a/test/automated/file-notify-tests.el +++ b/test/automated/file-notify-tests.el | |||
| @@ -61,6 +61,8 @@ | |||
| 61 | (defvar file-notify--test-results nil) | 61 | (defvar file-notify--test-results nil) |
| 62 | (defvar file-notify--test-event nil) | 62 | (defvar file-notify--test-event nil) |
| 63 | (defvar file-notify--test-events nil) | 63 | (defvar file-notify--test-events nil) |
| 64 | (defun file-notify--test-timeout () | ||
| 65 | (if (file-remote-p temporary-file-directory) 6 3)) | ||
| 64 | 66 | ||
| 65 | (defun file-notify--test-cleanup () | 67 | (defun file-notify--test-cleanup () |
| 66 | "Cleanup after a test." | 68 | "Cleanup after a test." |
| @@ -69,13 +71,16 @@ | |||
| 69 | (when (and file-notify--test-tmpfile | 71 | (when (and file-notify--test-tmpfile |
| 70 | (file-exists-p file-notify--test-tmpfile)) | 72 | (file-exists-p file-notify--test-tmpfile)) |
| 71 | (if (directory-name-p file-notify--test-tmpfile) | 73 | (if (directory-name-p file-notify--test-tmpfile) |
| 72 | (delete-directory file-notify--test-tmpfile) | 74 | (delete-directory file-notify--test-tmpfile 'recursive) |
| 73 | (delete-file file-notify--test-tmpfile))) | 75 | (delete-file file-notify--test-tmpfile))) |
| 74 | (when (and file-notify--test-tmpfile1 | 76 | (when (and file-notify--test-tmpfile1 |
| 75 | (file-exists-p file-notify--test-tmpfile1)) | 77 | (file-exists-p file-notify--test-tmpfile1)) |
| 76 | (if (directory-name-p file-notify--test-tmpfile1) | 78 | (if (directory-name-p file-notify--test-tmpfile1) |
| 77 | (delete-directory file-notify--test-tmpfile1) | 79 | (delete-directory file-notify--test-tmpfile1 'recursive) |
| 78 | (delete-file file-notify--test-tmpfile1))) | 80 | (delete-file file-notify--test-tmpfile1))) |
| 81 | (when (file-remote-p temporary-file-directory) | ||
| 82 | (tramp-cleanup-connection | ||
| 83 | (tramp-dissect-file-name temporary-file-directory) nil 'keep-password)) | ||
| 79 | 84 | ||
| 80 | (setq file-notify--test-tmpfile nil) | 85 | (setq file-notify--test-tmpfile nil) |
| 81 | (setq file-notify--test-tmpfile1 nil) | 86 | (setq file-notify--test-tmpfile1 nil) |
| @@ -150,6 +155,8 @@ being the result.") | |||
| 150 | (should | 155 | (should |
| 151 | (setq file-notify--test-desc | 156 | (setq file-notify--test-desc |
| 152 | (file-notify-add-watch temporary-file-directory '(change) 'ignore))) | 157 | (file-notify-add-watch temporary-file-directory '(change) 'ignore))) |
| 158 | |||
| 159 | ;; Cleanup. | ||
| 153 | (file-notify--test-cleanup)) | 160 | (file-notify--test-cleanup)) |
| 154 | 161 | ||
| 155 | (file-notify--deftest-remote file-notify-test00-availability | 162 | (file-notify--deftest-remote file-notify-test00-availability |
| @@ -190,6 +197,7 @@ being the result.") | |||
| 190 | (file-notify-add-watch temporary-file-directory '(change) 3)) | 197 | (file-notify-add-watch temporary-file-directory '(change) 3)) |
| 191 | '(wrong-type-argument 3))) | 198 | '(wrong-type-argument 3))) |
| 192 | 199 | ||
| 200 | ;; Cleanup. | ||
| 193 | (file-notify--test-cleanup)) | 201 | (file-notify--test-cleanup)) |
| 194 | 202 | ||
| 195 | (file-notify--deftest-remote file-notify-test01-add-watch | 203 | (file-notify--deftest-remote file-notify-test01-add-watch |
| @@ -215,11 +223,11 @@ is bound somewhere." | |||
| 215 | 223 | ||
| 216 | (defun file-notify--test-event-handler (event) | 224 | (defun file-notify--test-event-handler (event) |
| 217 | "Run a test over FILE-NOTIFY--TEST-EVENT. | 225 | "Run a test over FILE-NOTIFY--TEST-EVENT. |
| 218 | For later analysis, append the test result to | 226 | For later analysis, append the test result to `file-notify--test-results' |
| 219 | `file-notify--test-results' and the event to | 227 | and the event to `file-notify--test-events'." |
| 220 | `file-notify--test-events'." | ||
| 221 | (let* ((file-notify--test-event event) | 228 | (let* ((file-notify--test-event event) |
| 222 | (result (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) | 229 | (result |
| 230 | (ert-run-test (make-ert-test :body 'file-notify--test-event-test)))) | ||
| 223 | (setq file-notify--test-events | 231 | (setq file-notify--test-events |
| 224 | (append file-notify--test-events `(,file-notify--test-event))) | 232 | (append file-notify--test-events `(,file-notify--test-event))) |
| 225 | (setq file-notify--test-results | 233 | (setq file-notify--test-results |
| @@ -243,7 +251,7 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 243 | (declare (indent 3)) | 251 | (declare (indent 3)) |
| 244 | (let ((outer (make-symbol "outer"))) | 252 | (let ((outer (make-symbol "outer"))) |
| 245 | `(let ((,outer file-notify--test-events)) | 253 | `(let ((,outer file-notify--test-events)) |
| 246 | (let ((file-notify--test-events nil)) | 254 | (let (file-notify--test-events) |
| 247 | ,@body | 255 | ,@body |
| 248 | (file-notify--wait-for-events | 256 | (file-notify--wait-for-events |
| 249 | ,timeout (= ,n (length file-notify--test-events))) | 257 | ,timeout (= ,n (length file-notify--test-events))) |
| @@ -256,9 +264,7 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 256 | (skip-unless (file-notify--test-local-enabled)) | 264 | (skip-unless (file-notify--test-local-enabled)) |
| 257 | (unwind-protect | 265 | (unwind-protect |
| 258 | (progn | 266 | (progn |
| 259 | (setq file-notify--test-results nil | 267 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) |
| 260 | file-notify--test-events nil | ||
| 261 | file-notify--test-tmpfile (file-notify--test-make-temp-name) | ||
| 262 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) | 268 | file-notify--test-tmpfile1 (file-notify--test-make-temp-name) |
| 263 | file-notify--test-desc | 269 | file-notify--test-desc |
| 264 | (file-notify-add-watch | 270 | (file-notify-add-watch |
| @@ -268,41 +274,66 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 268 | 274 | ||
| 269 | ;; Check creation, change, and deletion. | 275 | ;; Check creation, change, and deletion. |
| 270 | (file-notify--test-with-events | 276 | (file-notify--test-with-events |
| 271 | 3 3 (lambda (events) | 277 | 3 (file-notify--test-timeout) |
| 272 | (should (equal '(created changed deleted) | 278 | (lambda (events) |
| 273 | (mapcar #'cadr events)))) | 279 | (should (equal '(created changed deleted) |
| 280 | (mapcar #'cadr events)))) | ||
| 274 | (write-region | 281 | (write-region |
| 275 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 282 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 276 | (delete-file file-notify--test-tmpfile)) | 283 | (delete-file file-notify--test-tmpfile)) |
| 277 | 284 | ||
| 278 | ;; Check copy. | 285 | ;; Check copy. |
| 279 | (file-notify--test-with-events | 286 | (file-notify--test-with-events |
| 280 | 3 3 (lambda (events) | 287 | 3 (file-notify--test-timeout) |
| 281 | (should (equal '(created changed deleted) | 288 | (lambda (events) |
| 282 | (mapcar #'cadr events)))) | 289 | (should (equal '(created changed deleted) |
| 290 | (mapcar #'cadr events)))) | ||
| 283 | (write-region | 291 | (write-region |
| 284 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 292 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 285 | (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) | 293 | (copy-file file-notify--test-tmpfile file-notify--test-tmpfile1) |
| 294 | ;; The next two events shall not be visible. | ||
| 295 | (set-file-modes file-notify--test-tmpfile 000) | ||
| 296 | (set-file-times file-notify--test-tmpfile '(0 0)) | ||
| 286 | (delete-file file-notify--test-tmpfile) | 297 | (delete-file file-notify--test-tmpfile) |
| 287 | (delete-file file-notify--test-tmpfile1)) | 298 | (delete-file file-notify--test-tmpfile1)) |
| 288 | 299 | ||
| 289 | ;; Check rename. | 300 | ;; Check rename. |
| 290 | (file-notify--test-with-events | 301 | (file-notify--test-with-events |
| 291 | 3 3 (lambda (events) | 302 | 3 (file-notify--test-timeout) |
| 292 | (should (equal '(created changed renamed) | 303 | (lambda (events) |
| 293 | (mapcar #'cadr events)))) | 304 | (should (equal '(created changed renamed) |
| 305 | (mapcar #'cadr events)))) | ||
| 294 | (write-region | 306 | (write-region |
| 295 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 307 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| 296 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) | 308 | (rename-file file-notify--test-tmpfile file-notify--test-tmpfile1) |
| 297 | ;; After the rename, we won't get events anymore. | 309 | ;; After the rename, we won't get events anymore. |
| 298 | (delete-file file-notify--test-tmpfile1)) | 310 | (delete-file file-notify--test-tmpfile1)) |
| 299 | 311 | ||
| 312 | ;; Check attribute change. | ||
| 313 | (file-notify-rm-watch file-notify--test-desc) | ||
| 314 | (setq file-notify--test-desc | ||
| 315 | (file-notify-add-watch | ||
| 316 | file-notify--test-tmpfile | ||
| 317 | '(attribute-change) 'file-notify--test-event-handler)) | ||
| 318 | (file-notify--test-with-events | ||
| 319 | 2 (file-notify--test-timeout) | ||
| 320 | (lambda (events) | ||
| 321 | (should (equal '(attribute-changed attribute-changed) | ||
| 322 | (mapcar #'cadr events)))) | ||
| 323 | (write-region | ||
| 324 | "any text" nil file-notify--test-tmpfile nil 'no-message) | ||
| 325 | (set-file-modes file-notify--test-tmpfile 000) | ||
| 326 | (read-event nil nil 0.1) ; In order to distinguish the events. | ||
| 327 | (set-file-times file-notify--test-tmpfile '(0 0)) | ||
| 328 | (delete-file file-notify--test-tmpfile)) | ||
| 329 | |||
| 300 | ;; Check the global sequence again just to make sure that | 330 | ;; Check the global sequence again just to make sure that |
| 301 | ;; `file-notify--test-events' has been set correctly. | 331 | ;; `file-notify--test-events' has been set correctly. |
| 302 | (should (equal (mapcar #'cadr file-notify--test-events) | 332 | (should (equal (mapcar #'cadr file-notify--test-events) |
| 303 | '(created changed deleted | 333 | '(created changed deleted |
| 304 | created changed deleted | 334 | created changed deleted |
| 305 | created changed renamed))) | 335 | created changed renamed |
| 336 | attribute-changed attribute-changed))) | ||
| 306 | 337 | ||
| 307 | (should file-notify--test-results) | 338 | (should file-notify--test-results) |
| 308 | (dolist (result file-notify--test-results) | 339 | (dolist (result file-notify--test-results) |
| @@ -310,6 +341,8 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 310 | (when (ert-test-failed-p result) | 341 | (when (ert-test-failed-p result) |
| 311 | (ert-fail | 342 | (ert-fail |
| 312 | (cadr (ert-test-result-with-condition-condition result)))))) | 343 | (cadr (ert-test-result-with-condition-condition result)))))) |
| 344 | |||
| 345 | ;; Cleanup. | ||
| 313 | (file-notify--test-cleanup))) | 346 | (file-notify--test-cleanup))) |
| 314 | 347 | ||
| 315 | (file-notify--deftest-remote file-notify-test02-events | 348 | (file-notify--deftest-remote file-notify-test02-events |
| @@ -367,7 +400,7 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 367 | (buffer-string)))) | 400 | (buffer-string)))) |
| 368 | (should (string-match "another text" (buffer-string))))) | 401 | (should (string-match "another text" (buffer-string))))) |
| 369 | 402 | ||
| 370 | ;; Exit. | 403 | ;; Cleanup. |
| 371 | (ignore-errors (kill-buffer buf)) | 404 | (ignore-errors (kill-buffer buf)) |
| 372 | (file-notify--test-cleanup)))) | 405 | (file-notify--test-cleanup)))) |
| 373 | 406 | ||
| @@ -377,6 +410,31 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 377 | (ert-deftest file-notify-test04-file-validity () | 410 | (ert-deftest file-notify-test04-file-validity () |
| 378 | "Check `file-notify-valid-p' for files." | 411 | "Check `file-notify-valid-p' for files." |
| 379 | (skip-unless (file-notify--test-local-enabled)) | 412 | (skip-unless (file-notify--test-local-enabled)) |
| 413 | |||
| 414 | (unwind-protect | ||
| 415 | (progn | ||
| 416 | (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) | ||
| 417 | (setq file-notify--test-desc (file-notify-add-watch | ||
| 418 | file-notify--test-tmpfile | ||
| 419 | '(change) | ||
| 420 | #'file-notify--test-event-handler)) | ||
| 421 | (file-notify--test-with-events | ||
| 422 | 2 (file-notify--test-timeout) | ||
| 423 | (lambda (events) | ||
| 424 | (should (equal '(created changed) | ||
| 425 | (mapcar #'cadr events)))) | ||
| 426 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 427 | (write-region | ||
| 428 | "any text" nil file-notify--test-tmpfile nil 'no-message) | ||
| 429 | (should (file-notify-valid-p file-notify--test-desc))) | ||
| 430 | ;; After removing the watch, the descriptor must not be valid | ||
| 431 | ;; anymore. | ||
| 432 | (file-notify-rm-watch file-notify--test-desc) | ||
| 433 | (should-not (file-notify-valid-p file-notify--test-desc))) | ||
| 434 | |||
| 435 | ;; Cleanup. | ||
| 436 | (file-notify--test-cleanup)) | ||
| 437 | |||
| 380 | ;; The batch-mode operation of w32notify is fragile (there's no | 438 | ;; The batch-mode operation of w32notify is fragile (there's no |
| 381 | ;; input threads to send the message to). | 439 | ;; input threads to send the message to). |
| 382 | (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify)))) | 440 | (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify)))) |
| @@ -389,9 +447,10 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 389 | '(change) | 447 | '(change) |
| 390 | #'file-notify--test-event-handler)) | 448 | #'file-notify--test-event-handler)) |
| 391 | (file-notify--test-with-events | 449 | (file-notify--test-with-events |
| 392 | 2 3 (lambda (events) | 450 | 2 (file-notify--test-timeout) |
| 393 | (should (equal '(created changed) | 451 | (lambda (events) |
| 394 | (mapcar #'cadr events)))) | 452 | (should (equal '(created changed) |
| 453 | (mapcar #'cadr events)))) | ||
| 395 | (should (file-notify-valid-p file-notify--test-desc)) | 454 | (should (file-notify-valid-p file-notify--test-desc)) |
| 396 | (write-region | 455 | (write-region |
| 397 | "any text" nil file-notify--test-tmpfile nil 'no-message) | 456 | "any text" nil file-notify--test-tmpfile nil 'no-message) |
| @@ -399,10 +458,12 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 399 | ;; After deleting the parent, the descriptor must not be valid | 458 | ;; After deleting the parent, the descriptor must not be valid |
| 400 | ;; anymore. | 459 | ;; anymore. |
| 401 | (delete-directory temporary-file-directory t) | 460 | (delete-directory temporary-file-directory t) |
| 402 | (read-event nil nil 0.5) | 461 | (file-notify--wait-for-events |
| 462 | (file-notify--test-timeout) | ||
| 463 | (not (file-notify-valid-p file-notify--test-desc))) | ||
| 403 | (should-not (file-notify-valid-p file-notify--test-desc))) | 464 | (should-not (file-notify-valid-p file-notify--test-desc))) |
| 404 | 465 | ||
| 405 | ;; Exit. | 466 | ;; Cleanup. |
| 406 | (file-notify--test-cleanup))) | 467 | (file-notify--test-cleanup))) |
| 407 | 468 | ||
| 408 | (file-notify--deftest-remote file-notify-test04-file-validity | 469 | (file-notify--deftest-remote file-notify-test04-file-validity |
| @@ -411,6 +472,25 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 411 | (ert-deftest file-notify-test05-dir-validity () | 472 | (ert-deftest file-notify-test05-dir-validity () |
| 412 | "Check `file-notify-valid-p' for directories." | 473 | "Check `file-notify-valid-p' for directories." |
| 413 | (skip-unless (file-notify--test-local-enabled)) | 474 | (skip-unless (file-notify--test-local-enabled)) |
| 475 | |||
| 476 | (unwind-protect | ||
| 477 | (progn | ||
| 478 | (setq file-notify--test-tmpfile (file-name-as-directory | ||
| 479 | (file-notify--test-make-temp-name))) | ||
| 480 | (make-directory file-notify--test-tmpfile) | ||
| 481 | (setq file-notify--test-desc (file-notify-add-watch | ||
| 482 | file-notify--test-tmpfile | ||
| 483 | '(change) | ||
| 484 | #'file-notify--test-event-handler)) | ||
| 485 | (should (file-notify-valid-p file-notify--test-desc)) | ||
| 486 | ;; After removing the watch, the descriptor must not be valid | ||
| 487 | ;; anymore. | ||
| 488 | (file-notify-rm-watch file-notify--test-desc) | ||
| 489 | (should-not (file-notify-valid-p file-notify--test-desc))) | ||
| 490 | |||
| 491 | ;; Cleanup. | ||
| 492 | (file-notify--test-cleanup)) | ||
| 493 | |||
| 414 | ;; The batch-mode operation of w32notify is fragile (there's no | 494 | ;; The batch-mode operation of w32notify is fragile (there's no |
| 415 | ;; input threads to send the message to). | 495 | ;; input threads to send the message to). |
| 416 | (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify)))) | 496 | (skip-unless (not (and noninteractive (eq file-notify--library 'w32notify)))) |
| @@ -424,13 +504,15 @@ Don't wait longer than TIMEOUT seconds for the events to be delivered." | |||
| 424 | '(change) | 504 | '(change) |
| 425 | #'file-notify--test-event-handler)) | 505 | #'file-notify--test-event-handler)) |
| 426 | (should (file-notify-valid-p file-notify--test-desc)) | 506 | (should (file-notify-valid-p file-notify--test-desc)) |
| 427 | (delete-directory file-notify--test-tmpfile t) | ||
| 428 | ;; After deleting the directory, the descriptor must not be | 507 | ;; After deleting the directory, the descriptor must not be |
| 429 | ;; valid anymore. | 508 | ;; valid anymore. |
| 430 | (read-event nil nil 0.5) | 509 | (delete-directory file-notify--test-tmpfile t) |
| 510 | (file-notify--wait-for-events | ||
| 511 | (file-notify--test-timeout) | ||
| 512 | (not (file-notify-valid-p file-notify--test-desc))) | ||
| 431 | (should-not (file-notify-valid-p file-notify--test-desc))) | 513 | (should-not (file-notify-valid-p file-notify--test-desc))) |
| 432 | 514 | ||
| 433 | ;; Exit. | 515 | ;; Cleanup. |
| 434 | (file-notify--test-cleanup))) | 516 | (file-notify--test-cleanup))) |
| 435 | 517 | ||
| 436 | (file-notify--deftest-remote file-notify-test05-dir-validity | 518 | (file-notify--deftest-remote file-notify-test05-dir-validity |