Resolving the last of the selftest thread hangs

Martin (gzlist) gzlist at googlemail.com
Thu Oct 7 08:03:04 BST 2010


Since merging the thread leak fixes, the selftest has taken more than
twenty minutes longer to complete here. It has also clashed with my
attempt to get cases dereferenced after being run to let machines
without lots of memory use the full suite, as merging that now results
in lots of extra failures.

The problem turns out to be an interaction between lazy imports and
the attempt to override the get_transport function. Fixing the
semantics would resolve both issues, but I'd like some input on how
this should be done.


For background on see the merge proposal and comments:

<https://code.launchpad.net/~vila/bzr/leaking-tests-catch-them-all/+merge/28336>


With timings now working through subunit (or shortly, when the
relevant branches get merged), it's possible to see that some test
modules take minutes to run:

<http://babune.ladeuil.net:24842/job/selftest-windows/190/testReport/>


The leaks branch adds this code to the setUp method of
TestCaseWithMemoryTransport to ensure transports get cleaned up rather
than hanging around after the test finishes:

    def get_transport_with_cleanup(*args, **kwargs):
        t = orig_get_transport(*args, **kwargs)
        if isinstance(t, _mod_transport.ConnectedTransport):
            self.addCleanup(t.disconnect)
        return t

    orig_get_transport = self.overrideAttr(_mod_transport, '_get_transport',
                                           get_transport_with_cleanup)


However, bzrlib.bzrdir and others have imports in the fashion:

    from bzrlib.lazy_import import lazy_import
    lazy_import(globals(), """
    ...
    from bzrlib.transport import (
        do_catching_redirections,
        get_transport,
        local,
        )
    ...
    """)

This can mean the get_transport function points to some random
already-run test that happened to be the first to trigger the lazy
import.


Either get_transport always needs to be accessed as an attribute on
the module, or the test override needs turning into something more
robust in ensuring disconnect gets called on all transports. On IRC
vila has just suggested adding a hook triggered when a transport
connects. I'd also like lazy import to be better at avoiding this kind
of hard to find breakage, and ideally be globally disableable to help
debugging.

Martin



More information about the bazaar mailing list