Change in vdsm[master]: utils: add weakmethod helper

nsoffer at redhat.com nsoffer at redhat.com
Mon Jan 18 23:23:19 UTC 2016


Nir Soffer has posted comments on this change.

Change subject: utils: add weakmethod helper
......................................................................


Patch Set 10:

(4 comments)

https://gerrit.ovirt.org/#/c/51865/10/tests/utilsTests.py
File tests/utilsTests.py:

Line 1034:             self.assertEquals(obj.public(), ("public", (), {}))
Line 1035:             del obj
Line 1036: 
Line 1037:             gc.collect()
Line 1038:             assert len(gc.garbage) == 1
These asserts are fine when using py.test, but with nose we get bad output when if it fails. We should use unitest asserts until we move to py.test.
Line 1039:             assert ObjectWithDel == type(gc.garbage[0])
Line 1040:             gc.garbage[0].public = None  # break the cycle
Line 1041:             del gc.garbage[0]  # we need to do explicitely to avoid leaks
Line 1042: 


Line 1037:             gc.collect()
Line 1038:             assert len(gc.garbage) == 1
Line 1039:             assert ObjectWithDel == type(gc.garbage[0])
Line 1040:             gc.garbage[0].public = None  # break the cycle
Line 1041:             del gc.garbage[0]  # we need to do explicitely to avoid leaks
We can get rid of garbage from the test in the context manager:

    finally:
        del gc.garbage[:]
        gc.garbage.extend(saved_garbage)
        ...

This is safer, we don't have to cleanup in the test.
Line 1042: 
Line 1043:             # not needed by the test, but we don't want to pollute
Line 1044:             # the global environment.
Line 1045:             self.assertNoGarbage()


Line 1041:             del gc.garbage[0]  # we need to do explicitely to avoid leaks
Line 1042: 
Line 1043:             # not needed by the test, but we don't want to pollute
Line 1044:             # the global environment.
Line 1045:             self.assertNoGarbage()
This is not needed now if you handle garbage from the test in the context manager.
Line 1046: 
Line 1047:     def test_without_reference_cycle(self):
Line 1048: 
Line 1049:         with _debug_gc():


Line 1065:     def assertNoGarbage(self):
Line 1066:         gc.collect()
Line 1067:         # only to help troubleshooting should the assert fail
Line 1068:         print(gc.garbage)
Line 1069:         assert not gc.garbage
If you use assertEqual(gc.garbage, []) we don't need the print
Line 1070: 
Line 1071: 
Line 1072: class NoIntrPollTests(TestCaseBase):
Line 1073:     RETRIES = 3


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I9f26aa314e26142122e9f594275406cf7fbade98
Gerrit-PatchSet: 10
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Martin Polednik <mpolednik at redhat.com>
Gerrit-Reviewer: Milan Zamazal <mzamazal at redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski at gmail.com>
Gerrit-Reviewer: Vinzenz Feenstra <vfeenstr at redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes


More information about the vdsm-patches mailing list