Change in vdsm[master]: tests: lib: add tests for utils.weakmethod
fromani at redhat.com
fromani at redhat.com
Thu Jan 21 12:26:24 UTC 2016
Francesco Romani has posted comments on this change.
Change subject: tests: lib: add tests for utils.weakmethod
......................................................................
Patch Set 1:
(5 comments)
https://gerrit.ovirt.org/#/c/52408/1/tests/utilsTests.py
File tests/utilsTests.py:
Line 1005:
Line 1006: @contextlib.contextmanager
Line 1007: def _debug_gc():
Line 1008: saved_flags = gc.get_debug()
Line 1009: saved_garbage = gc.garbage[:]
> This prooved useless, once you call gc.collect() the garbage will come back
OK, so in this context manager I'll just save and restore the gc flags
Line 1010: del gc.garbage[:]
Line 1011: try:
Line 1012: gc.set_debug(0)
Line 1013: yield
Line 1011: try:
Line 1012: gc.set_debug(0)
Line 1013: yield
Line 1014: finally:
Line 1015: del gc.garbage[:] # we need to do explicitely to avoid leaks
> This may be useful, in case a test broke a cycle, but left an object in the
Agreed. Better to be done in one place, and that place should be the test itself, out of necessity.
Line 1016: gc.garbage.extend(saved_garbage)
Line 1017: gc.set_debug(saved_flags)
Line 1018:
Line 1019:
Line 1036: del obj
Line 1037:
Line 1038: gc.collect()
Line 1039: self.assertEquals(len(gc.garbage), 1)
Line 1040: self.assertEquals(ObjectWithDel, type(gc.garbage[0]))
> Both tests will break if another tests leaked some objects, and we don't wa
ok, will revert
Line 1041: gc.garbage[0].public = None # break the cycle
Line 1042:
Line 1043: # not needed by the test, but this test *intentionally* leaks, and
Line 1044: # we want to make sure we don't pollute the global environment.
Line 1041: gc.garbage[0].public = None # break the cycle
Line 1042:
Line 1043: # not needed by the test, but this test *intentionally* leaks, and
Line 1044: # we want to make sure we don't pollute the global environment.
Line 1045: self.assertNoGarbage()
> We cannot do this check.
Yes, not now, the environment is too noisy
Line 1046:
Line 1047: def test_without_reference_cycle(self):
Line 1048:
Line 1049: with _debug_gc():
Line 1051: obj.public = utils.weakmethod(obj.public)
Line 1052: self.assertEquals(obj.public(), ("public", (), {}))
Line 1053: del obj
Line 1054:
Line 1055: self.assertNoGarbage()
> We should search gc.garbage and verify that there is no instance of ObjectW
Done
Line 1056:
Line 1057: def test_raise_on_invalid_weakref(self):
Line 1058: obj = ObjectWithDel()
Line 1059: method = utils.weakmethod(obj.public)
--
To view, visit https://gerrit.ovirt.org/52408
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I7f0b8642f3fafef28a76ee9cfaa481a73ddaf6aa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani at redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer at redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation at ovirt.org>
Gerrit-HasComments: Yes
More information about the vdsm-patches
mailing list