/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Merge transport_post_connect_hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
2732
2732
 
2733
2733
    def setUp(self):
2734
2734
        super(TestCaseWithMemoryTransport, self).setUp()
2735
 
        # Ensure that ConnectedTransport doesn't leak sockets
2736
 
        def get_transport_from_url_with_cleanup(*args, **kwargs):
2737
 
            t = orig_get_transport_from_url(*args, **kwargs)
2738
 
            if isinstance(t, _mod_transport.ConnectedTransport):
2739
 
                self.addCleanup(t.disconnect)
2740
 
            return t
2741
 
 
2742
 
        orig_get_transport_from_url = self.overrideAttr(
2743
 
            _mod_transport, 'get_transport_from_url',
2744
 
            get_transport_from_url_with_cleanup)
 
2735
 
 
2736
        def _add_disconnect_cleanup(transport):
 
2737
            """Schedule disconnection of given transport at test cleanup
 
2738
 
 
2739
            This needs to happen for all connected transports or leaks occur.
 
2740
 
 
2741
            Note reconnections may mean we call disconnect multiple times per
 
2742
            transport which is suboptimal but seems harmless.
 
2743
            """
 
2744
            self.addCleanup(transport.disconnect)
 
2745
 
 
2746
        _mod_transport.Transport.hooks.install_named_hook('post_connect',
 
2747
            _add_disconnect_cleanup, None)
 
2748
 
2745
2749
        self._make_test_root()
2746
2750
        self.addCleanup(os.chdir, os.getcwdu())
2747
2751
        self.makeAndChdirToTestDir()