diff options
author | Philipp Stephani <phst@google.com> | 2020-01-04 12:34:10 +0100 |
---|---|---|
committer | Philipp Stephani <phst@google.com> | 2020-01-04 12:34:10 +0100 |
commit | fb38d367f4a46c580510f8a6510ae8fb5f39222f (patch) | |
tree | fbe83be23ee338e23ce409448f182b65c07fbf13 /test/src/emacs-module-tests.el | |
parent | 52db14b0dc5a93d7a7219917b8f603b14f94f24f (diff) | |
download | emacs-fb38d367f4a46c580510f8a6510ae8fb5f39222f.tar.gz emacs-fb38d367f4a46c580510f8a6510ae8fb5f39222f.tar.bz2 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/emacs-module-tests.el')
-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." (delete-file so)))) (ert-deftest module/function-finalizer () - (mod-test-make-function-with-finalizer) - (let* ((previous-calls (mod-test-function-finalizer-calls)) - (expected-calls (copy-sequence previous-calls))) - (cl-incf (car expected-calls)) + "Test that module function finalizers are properly called." + ;; We create and leak a couple of module functions with attached + ;; finalizer. Creating only one function risks spilling it to the + ;; stack, where it wouldn't be garbage-collected. However, with one + ;; hundred functions, there should be at least one that's + ;; unreachable. + (dotimes (_ 100) + (mod-test-make-function-with-finalizer)) + (cl-destructuring-bind (valid-before invalid-before) + (mod-test-function-finalizer-calls) + (should (zerop invalid-before)) (garbage-collect) - (should (equal (mod-test-function-finalizer-calls) expected-calls)))) + (cl-destructuring-bind (valid-after invalid-after) + (mod-test-function-finalizer-calls) + (should (zerop invalid-after)) + ;; We don't require exactly 100 invocations of the finalizer, + ;; but at least one. + (should (> valid-after valid-before))))) ;;; emacs-module-tests.el ends here |