[pygobject] tests: Add skipped test for GLib.Source inheritance problems



commit df21dbbc84fa319af2a0f0664de436ca30df616e
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Jan 16 16:33:41 2014 -0800

    tests: Add skipped test for GLib.Source inheritance problems
    
    Add test showing memory problems with sub-classes of GLib.Source.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722387

 tests/test_source.py |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/tests/test_source.py b/tests/test_source.py
index 6f69927..e0910f9 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -220,6 +220,51 @@ class TestSource(unittest.TestCase):
         del source
         self.assertTrue(self.finalized)
 
+    @unittest.skip('https://bugzilla.gnome.org/show_bug.cgi?id=722387')
+    def test_python_unref_with_active_source(self):
+        # Tests a Python derived Source which is free'd in the context of
+        # Python, but remains active in the MainContext (via source.attach())
+        self.dispatched = False
+        self.finalized = False
+
+        class S(GLib.Source):
+            def prepare(s):
+                return (True, 1)
+
+            def check(s):
+                pass
+
+            def dispatch(s, callback, args):
+                self.dispatched = True
+                return False
+
+            def finalize(s):
+                self.finalized = True
+
+        source = S()
+        id = source.attach()
+        self.assertFalse(self.finalized)
+        self.assertFalse(source.is_destroyed())
+
+        # Delete the source from Python but should still remain
+        # active in the main context.
+        del source
+
+        context = GLib.MainContext.default()
+        while context.iteration(may_block=False):
+            pass
+
+        self.assertTrue(self.dispatched)
+        self.assertFalse(self.finalized)
+
+        source = context.find_source_by_id(id)
+        source.destroy()  # Remove from main context.
+        self.assertTrue(source.is_destroyed())
+
+        # Source should be finalized called after del
+        del source
+        self.assertTrue(self.finalized)
+
     def test_extra_init_args(self):
         class SourceWithInitArgs(GLib.Source):
             def __init__(self, arg, kwarg=None):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]