[PATCH] selftest: close connections after tests in samba4.ldap.acl.python

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Tue Jan 9 19:06:36 UTC 2018

Something like this:

--- a/python/samba/tests/__init__.py
+++ b/python/samba/tests/__init__.py
@@ -52,8 +52,14 @@ HEXDUMP_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(
 class TestCase(unittest.TestCase):
     """A Samba test case."""
+    def clean_up_dangling_ldbs(self):
+        for k, v in self.__dict__.items():
+            if isinstance(v, samba.Ldb):
+                del self.__dict__[k]
     def setUp(self):
         super(TestCase, self).setUp()
+        self.addCleanup(self.clean_up_dangling_ldbs)
         test_debug_level = os.getenv("TEST_DEBUG_LEVEL")
         if test_debug_level is not None:
             test_debug_level = int(test_debug_level)

would ensure that all ldbs get tidied up just after the last moment
they could be of any possible use (rather than at subprocess death).

While it doesn't ensure the ldbs get deleted in a particular order
*within* the test (as Jamie's patch does), it does mean they are
deleted in a deterministic order *across* tests, rather than in the
higgledy-piggledy hash order they are now.

I don't know if this different determinism is useful or how much
memory is saved. Unfortunately the only evidence I have after two runs
is that it seems to make the whole thing slightly slower.


More information about the samba-technical mailing list