From 970a92bb514767851dd6e3644fe88bfae9d8660f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 19 Nov 2015 17:58:49 +0100 Subject: [PATCH] spec for gears.object: Test weak signals better Since weak signals specifically exist to do magic with the garbage collector, do a couple of garbage collection cycles and verify that this does not disconnect the callback function prematurely (the function is kept alive since it is a local variable). (I actually did a mistake that makes this enhanced test fail and fixed it before committing) Signed-off-by: Uli Schlachter --- spec/gears/object_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/gears/object_spec.lua b/spec/gears/object_spec.lua index 692e9fd1..17a0dcae 100644 --- a/spec/gears/object_spec.lua +++ b/spec/gears/object_spec.lua @@ -52,6 +52,12 @@ describe("gears.object", function() called = true end obj:weak_connect_signal("signal", cb) + + -- Check that the GC doesn't disconnect the signal + for i = 1, 10 do + collectgarbage("collect") + end + obj:emit_signal("signal") assert.is_true(called) end)