Change in vdsm[master]: lib: fix too early collection with weakmethod

fromani at redhat.com fromani at redhat.com
Tue Mar 15 09:11:33 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: lib: fix too early collection with weakmethod
......................................................................

lib: fix too early collection with weakmethod

WIP
This is start to reproduce and understand why
the object is collected so early.

The test works (reproduces) but is still too crude.

Change-Id: Ie27fc8f1c746c7cd9b48afaa89e9660b5111896c
Related-To: https://bugzilla.redhat.com/1305338
Related-To: https://gerrit.ovirt.org/#/c/53160/
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/utilsTests.py
1 file changed, 39 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/05/53205/1

diff --git a/tests/utilsTests.py b/tests/utilsTests.py
index c8b4d17..014e866 100644
--- a/tests/utilsTests.py
+++ b/tests/utilsTests.py
@@ -25,6 +25,7 @@
 import cpopen
 import errno
 import fcntl
+import functools
 import gc
 import logging
 import operator
@@ -907,6 +908,39 @@
         print('__del__', self.__class__.__name__)
 
 
+class ObjectWithDelBuilder(object):
+
+    def make_object(self):
+        return ObjectWithDel()
+
+    def __del__(self):
+        print('__del__', self.__class__.__name__)
+
+
+def wrapMethod(f):
+    @functools.wraps(f)
+    def wrapper(*args, **kwargs):
+        ret = f(*args, **kwargs)
+        if isinstance(ret, ObjectWithDel):
+            for name in dir(ret):
+                method = getattr(ret, name)
+                if callable(method) and name[0] != '_':
+                    setattr(ret, name,
+                            wrapMethod(utils.weakmethod(method)))
+        return ret
+    return wrapper
+
+
+def make_builder():
+    builder = ObjectWithDelBuilder()
+    for name in dir(ObjectWithDelBuilder):
+        method = getattr(builder, name)
+        if callable(method) and name[0] != '_':
+            setattr(builder, name,
+                    wrapMethod(utils.weakmethod(method)))
+    return builder
+
+
 class TestWeakmethod(TestCaseBase):
 
     def setUp(self):
@@ -952,6 +986,11 @@
         del obj
         self.assertRaises(utils.InvalidatedWeakRef, method)
 
+    def test_virdomain_wrapper(self):
+        b = make_builder()
+        self.assertEquals(b.make_object().public(),
+                          ("public", (), {}))
+
 
 class NoIntrPollTests(TestCaseBase):
     RETRIES = 3


-- 
To view, visit https://gerrit.ovirt.org/53205
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie27fc8f1c746c7cd9b48afaa89e9660b5111896c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>


More information about the vdsm-patches mailing list