Nir Soffer has uploaded a new change for review. Change subject: tests: Add tests for registering instancemethod ......................................................................
tests: Add tests for registering instancemethod Event class cannot be used with instance methods, so we must use partial holding weak reference to the object. This code is used in StoragePool, and these tests validate that this works and serve as example code for Event. Change-Id: Iba3d4626e3fffab9778364966bc82711c5f29472 Signed-off-by: Nir Soffer <nsof...@redhat.com> --- M tests/miscTests.py 1 file changed, 35 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/35438/1 diff --git a/tests/miscTests.py b/tests/miscTests.py index ecf5ba4..a955979 100644 --- a/tests/miscTests.py +++ b/tests/miscTests.py @@ -26,6 +26,10 @@ import signal import fcntl import errno +import weakref + +from functools import partial + from testlib import AssertingLock from testlib import VdsmTestCase as TestCaseBase from testlib import temporaryPath @@ -125,6 +129,37 @@ ev.wait(5) self.assertTrue(ev.isSet()) + def testInstanceMethod(self): + ev = threading.Event() + event = misc.Event("name", sync=True) + receiver = Receiver(event, ev) + print event._registrar + event.emit() + ev.wait(5) + self.assertTrue(ev.isSet()) + + def testInstanceMethodDead(self): + ev = threading.Event() + event = misc.Event("name", sync=True) + receiver = Receiver(event, ev) + print event._registrar + del receiver + print event._registrar + event.emit() + ev.wait(1) + self.assertFalse(ev.isSet()) + + +class Receiver(object): + + def __init__(self, event, flag): + self._callback = partial(Receiver.callback, weakref.proxy(self)) + event.register(self._callback) + self.flag = flag + + def callback(self): + self.flag.set() + class TMap(TestCaseBase): def test(self): -- To view, visit http://gerrit.ovirt.org/35438 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iba3d4626e3fffab9778364966bc82711c5f29472 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Nir Soffer <nsof...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches