Commit fb38d367 authored by Philipp Stephani's avatar Philipp Stephani

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.
parent 52db14b0
Pipeline #4479 passed with stage
in 80 minutes and 43 seconds
......@@ -403,11 +403,23 @@ See Bug#36226."
(delete-file so))))
(ert-deftest module/function-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)
(cl-destructuring-bind (valid-before invalid-before)
(should (zerop invalid-before))
(should (equal (mod-test-function-finalizer-calls) expected-calls))))
(cl-destructuring-bind (valid-after invalid-after)
(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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment