~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Ensure that all transports close their underlying connection.

* bzrlib/transport/sftp.py:
(SFTPTransport.disconnect): Close the sftp connection.

* bzrlib/transport/remote.py:
(RemoteTransport.disconnect): The medium can be None.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.disconnect): Close the http connection.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport.disconnect): Close the Curl object.

* bzrlib/transport/http/__init__.py:
(SmartClientHTTPMedium.disconnect): Disconnect the backing http
transport.

* bzrlib/transport/gio_transport.py:
(GioTransport.disconnect): Hmm, nothing obvious here.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport.disconnect): Close the ftplib connection.

* bzrlib/transport/__init__.py:
(Transport.disconnect): A do-nothing implementation by default.
(ConnectedTransport.disconnect): A new required method.

* bzrlib/tests/test_smart_transport.py:
(TestSmartTCPServer.test_get_error_unexpected)
(SmartTCPTests.start_server): Revert to SmartServer waiting for a
better way to capture the connections.

* bzrlib/tests/per_transport.py:
(TransportTests.test_connection_sharing): 'None' is better than
'object()' for a dummy connection.

* bzrlib/tests/__init__.py:
(TestCase._check_leaked_threads): Don't fail at first leak or all
subsequent tests will fail too. A more elaborate scheme would be
to use threading.enumerate() but that's a big hammer with little
benefits as long as there exist "valid" leaks (like the smart
server).
(TestCaseWithMemoryTransport.setUp): Make sure we call
transport.disconnect() for all created transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
831
831
 
832
832
    def _check_leaked_threads(self):
833
833
        active = threading.activeCount()
834
 
        self.assertEqual(1, active, '%r is leaking thread(s)' % self.id())
835
834
        leaked_threads = active - TestCase._active_threads
836
835
        TestCase._active_threads = active
837
836
        # If some tests make the number of threads *decrease*, we'll consider
2432
2431
 
2433
2432
    def setUp(self):
2434
2433
        super(TestCaseWithMemoryTransport, self).setUp()
 
2434
        # Ensure that ConnectedTransport doesn't leak sockets
 
2435
        def get_transport_with_cleanup(*args, **kwargs):
 
2436
            t = self._orig_get_transport(*args, **kwargs)
 
2437
            if isinstance(t, _mod_transport.ConnectedTransport):
 
2438
                self.addCleanup(t.disconnect)
 
2439
            return t
 
2440
 
 
2441
        self._orig_get_transport = self.overrideAttr(
 
2442
            _mod_transport, 'get_transport', get_transport_with_cleanup)
2435
2443
        self._make_test_root()
2436
2444
        self.addCleanup(os.chdir, os.getcwdu())
2437
2445
        self.makeAndChdirToTestDir()