diff options
| author | Philipp Stephani | 2020-01-04 12:34:10 +0100 |
|---|---|---|
| committer | Philipp Stephani | 2020-01-04 12:34:10 +0100 |
| commit | fb38d367f4a46c580510f8a6510ae8fb5f39222f (patch) | |
| tree | fbe83be23ee338e23ce409448f182b65c07fbf13 /test/src | |
| parent | 52db14b0dc5a93d7a7219917b8f603b14f94f24f (diff) | |
| download | emacs-fb38d367f4a46c580510f8a6510ae8fb5f39222f.tar.gz emacs-fb38d367f4a46c580510f8a6510ae8fb5f39222f.zip | |
Make module function finalizer test less brittle.
* test/src/emacs-module-tests.el (module/function-finalizer): Create
100 leaked functions to increase the probability that at least one
gets garbage-collected.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/emacs-module-tests.el | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 4f5871be5eb..c61abfdf683 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el | |||
| @@ -403,11 +403,23 @@ See Bug#36226." | |||
| 403 | (delete-file so)))) | 403 | (delete-file so)))) |
| 404 | 404 | ||
| 405 | (ert-deftest module/function-finalizer () | 405 | (ert-deftest module/function-finalizer () |
| 406 | (mod-test-make-function-with-finalizer) | 406 | "Test that module function finalizers are properly called." |
| 407 | (let* ((previous-calls (mod-test-function-finalizer-calls)) | 407 | ;; We create and leak a couple of module functions with attached |
| 408 | (expected-calls (copy-sequence previous-calls))) | 408 | ;; finalizer. Creating only one function risks spilling it to the |
| 409 | (cl-incf (car expected-calls)) | 409 | ;; stack, where it wouldn't be garbage-collected. However, with one |
| 410 | ;; hundred functions, there should be at least one that's | ||
| 411 | ;; unreachable. | ||
| 412 | (dotimes (_ 100) | ||
| 413 | (mod-test-make-function-with-finalizer)) | ||
| 414 | (cl-destructuring-bind (valid-before invalid-before) | ||
| 415 | (mod-test-function-finalizer-calls) | ||
| 416 | (should (zerop invalid-before)) | ||
| 410 | (garbage-collect) | 417 | (garbage-collect) |
| 411 | (should (equal (mod-test-function-finalizer-calls) expected-calls)))) | 418 | (cl-destructuring-bind (valid-after invalid-after) |
| 419 | (mod-test-function-finalizer-calls) | ||
| 420 | (should (zerop invalid-after)) | ||
| 421 | ;; We don't require exactly 100 invocations of the finalizer, | ||
| 422 | ;; but at least one. | ||
| 423 | (should (> valid-after valid-before))))) | ||
| 412 | 424 | ||
| 413 | ;;; emacs-module-tests.el ends here | 425 | ;;; emacs-module-tests.el ends here |