]> git.eshelyaron.com Git - emacs.git/commitdiff
Make module function finalizer test less brittle.
authorPhilipp Stephani <phst@google.com>
Sat, 4 Jan 2020 11:34:10 +0000 (12:34 +0100)
committerPhilipp Stephani <phst@google.com>
Sat, 4 Jan 2020 11:34:10 +0000 (12:34 +0100)
* test/src/emacs-module-tests.el (module/function-finalizer): Create
100 leaked functions to increase the probability that at least one
gets garbage-collected.

test/src/emacs-module-tests.el

index 4f5871be5eb11d1e3b4e70eaaf6f19a03f62105e..c61abfdf683cfa383056e35a97beb9c88d0aafa7 100644 (file)
@@ -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