Rev 5277: With most of the fixes for mgz to test in file:///home/vila/src/bzr/experimental/for-babune/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Jun 5 17:35:22 BST 2010


At file:///home/vila/src/bzr/experimental/for-babune/

------------------------------------------------------------
revno: 5277 [merge]
revision-id: v.ladeuil+lp at free.fr-20100605163521-u4iqsyyetweyo0hi
parent: v.ladeuil+lp at free.fr-20100605104253-ka13fy04ya0pxm3r
parent: v.ladeuil+lp at free.fr-20100605163107-6mjhnbwoz6nzpr1w
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: for-babune
timestamp: Sat 2010-06-05 18:35:21 +0200
message:
  With most of the fixes for mgz to test
modified:
  bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/per_transport.py  test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
  bzrlib/tests/test_server.py    test_server.py-20100209163834-im1ozfuenfmqaa2m-1
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
  bzrlib/transport/gio_transport.py __init__.py-20100430125031-jb4f7q7mtyz55kz3-2
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
  bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
  bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
  bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
-------------- next part --------------
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py	2010-05-24 01:05:14 +0000
+++ b/bzrlib/smart/server.py	2010-05-31 13:51:12 +0000
@@ -173,6 +173,9 @@
         thread_name = 'smart-server-child' + thread_name_suffix
         connection_thread = threading.Thread(
             None, handler.serve, name=thread_name)
+        # FIXME: This thread is never joined, it should at least be collected
+        # somewhere so that tests that want to check for leaked threads can get
+        # rid of them -- vila 20100531
         connection_thread.setDaemon(True)
         connection_thread.start()
         return connection_thread

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-06-02 14:50:04 +0000
+++ b/bzrlib/tests/__init__.py	2010-06-05 16:31:07 +0000
@@ -2431,6 +2431,15 @@
 
     def setUp(self):
         super(TestCaseWithMemoryTransport, self).setUp()
+        # Ensure that ConnectedTransport doesn't leak sockets
+        def get_transport_with_cleanup(*args, **kwargs):
+            t = self._orig_get_transport(*args, **kwargs)
+            if isinstance(t, _mod_transport.ConnectedTransport):
+                self.addCleanup(t.disconnect)
+            return t
+
+        self._orig_get_transport = self.overrideAttr(
+            _mod_transport, 'get_transport', get_transport_with_cleanup)
         self._make_test_root()
         self.addCleanup(os.chdir, os.getcwdu())
         self.makeAndChdirToTestDir()

=== modified file 'bzrlib/tests/per_transport.py'
--- a/bzrlib/tests/per_transport.py	2010-06-05 09:01:06 +0000
+++ b/bzrlib/tests/per_transport.py	2010-06-05 16:31:07 +0000
@@ -1264,7 +1264,7 @@
         self.assertIs(t._get_connection(), c._get_connection())
 
         # Temporary failure, we need to create a new dummy connection
-        new_connection = object()
+        new_connection = None
         t._set_connection(new_connection)
         # Check that both transports use the same connection
         self.assertIs(new_connection, t._get_connection())

=== modified file 'bzrlib/tests/test_server.py'
--- a/bzrlib/tests/test_server.py	2010-06-05 10:25:45 +0000
+++ b/bzrlib/tests/test_server.py	2010-06-05 16:26:37 +0000
@@ -260,9 +260,10 @@
         """Overrides Thread.run to capture any exception."""
         self.ready.clear()
         try:
-            super(ThreadWithException, self).run()
-        except:
-            self.exception = sys.exc_info()
+            try:
+                super(ThreadWithException, self).run()
+            except:
+                self.exception = sys.exc_info()
         finally:
             # Make sure the calling thread is released
             self.ready.set()

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2010-03-18 23:11:15 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2010-06-01 13:01:20 +0000
@@ -40,7 +40,9 @@
         server,
         vfs,
 )
-from bzrlib.tests import test_smart
+from bzrlib.tests import (
+    test_smart,
+    )
 from bzrlib.transport import (
         http,
         local,
@@ -1012,40 +1014,45 @@
             self.backing_transport = transport.get_transport(
                 "readonly+" + self.backing_transport.abspath('.'))
         self.server = server.SmartTCPServer(self.backing_transport)
+        # XXX: Shouldn't we calling self.server.start_server below instead of
+        # start_background_thread ? -- vila 20100531
         self.server.start_background_thread('-' + self.id())
         self.transport = remote.RemoteTCPTransport(self.server.get_url())
-        self.addCleanup(self.tearDownServer)
+        self.addCleanup(self.stop_server)
         self.permit_url(self.server.get_url())
 
-    def tearDownServer(self):
+    def stop_server(self):
+        """Disconnect the client and stop the server.
+
+        This must be re-entrant as some tests will call it explicitly in
+        addition to the normal cleanup.
+        """
         if getattr(self, 'transport', None):
             self.transport.disconnect()
             del self.transport
         if getattr(self, 'server', None):
             self.server.stop_background_thread()
-            # XXX: why not .stop_server() -- mbp 20100106
             del self.server
 
 
 class TestServerSocketUsage(SmartTCPTests):
 
-    def test_server_setup_teardown(self):
-        """It should be safe to teardown the server with no requests."""
+    def test_server_start_stop(self):
+        """It should be safe to stop the server with no requests."""
         self.start_server()
-        server = self.server
         transport = remote.RemoteTCPTransport(self.server.get_url())
-        self.tearDownServer()
+        self.stop_server()
         self.assertRaises(errors.ConnectionError, transport.has, '.')
 
     def test_server_closes_listening_sock_on_shutdown_after_request(self):
         """The server should close its listening socket when it's stopped."""
         self.start_server()
-        server = self.server
+        server_url = self.server.get_url()
         self.transport.has('.')
-        self.tearDownServer()
+        self.stop_server()
         # if the listening socket has closed, we should get a BADFD error
         # when connecting, rather than a hang.
-        transport = remote.RemoteTCPTransport(server.get_url())
+        transport = remote.RemoteTCPTransport(server_url)
         self.assertRaises(errors.ConnectionError, transport.has, '.')
 
 
@@ -1187,7 +1194,7 @@
         self.transport.has('.')
         self.assertEqual([], self.hook_calls)
         # clean up the server
-        self.tearDownServer()
+        self.stop_server()
         # now it should have fired.
         self.assertEqual(result, self.hook_calls)
 
@@ -1206,7 +1213,7 @@
         self.transport.has('.')
         self.assertEqual([], self.hook_calls)
         # clean up the server
-        self.tearDownServer()
+        self.stop_server()
         # now it should have fired.
         self.assertEqual(result, self.hook_calls)
 

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2010-05-30 16:26:11 +0000
+++ b/bzrlib/transport/__init__.py	2010-06-01 13:01:20 +0000
@@ -1286,6 +1286,12 @@
         # should be asked to ConnectedTransport only.
         return None
 
+    def disconnect(self):
+        # This is really needed for ConnectedTransport only, but it's easier to
+        # have Transport do nothing than testing that the disconnect should be
+        # asked to ConnectedTransport only.
+        pass
+
     def _redirected_to(self, source, target):
         """Returns a transport suitable to re-issue a redirected request.
 
@@ -1550,6 +1556,13 @@
             transport = self.__class__(other_base, _from_transport=self)
         return transport
 
+    def disconnect(self):
+        """Disconnect the transport.
+
+        If and when required the transport willl reconnect automatically.
+        """
+        raise NotImplementedError(self.disconnect)
+
 
 # We try to recognize an url lazily (ignoring user, password, etc)
 _urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<rest>.*)$')

=== modified file 'bzrlib/transport/ftp/__init__.py'
--- a/bzrlib/transport/ftp/__init__.py	2010-02-27 01:37:54 +0000
+++ b/bzrlib/transport/ftp/__init__.py	2010-06-01 13:01:20 +0000
@@ -164,6 +164,11 @@
         connection, credentials = self._create_connection(credentials)
         self._set_connection(connection, credentials)
 
+    def disconnect(self):
+        connection = self._get_connection()
+        if connection is not None:
+            connection.close()
+
     def _translate_ftp_error(self, err, path, extra=None,
                               unknown_exc=FtpPathError):
         """Try to translate an ftplib exception to a bzrlib exception.

=== modified file 'bzrlib/transport/gio_transport.py'
--- a/bzrlib/transport/gio_transport.py	2010-05-28 18:52:03 +0000
+++ b/bzrlib/transport/gio_transport.py	2010-06-01 13:01:20 +0000
@@ -235,7 +235,13 @@
                                         " %s" % str(e), orig_error=e)
         return connection, (user, password)
 
+    def disconnect(self):
+        # FIXME: Nothing seems to be necessary here, which sounds a bit strange
+        # -- vila 20100601
+        pass
+
     def _reconnect(self):
+        # FIXME: This doesn't seem to be used -- vila 20100601
         """Create a new connection with the previously used credentials"""
         credentials = self._get_credentials()
         connection, credentials = self._create_connection(credentials)

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/transport/http/__init__.py	2010-06-01 13:01:20 +0000
@@ -629,6 +629,11 @@
         """
         pass
 
+    def disconnect(self):
+        """See SmartClientMedium.disconnect()."""
+        t = self._http_transport_ref()
+        t.disconnect()
+
 
 # TODO: May be better located in smart/medium.py with the other
 # SmartMediumRequest classes

=== modified file 'bzrlib/transport/http/_pycurl.py'
--- a/bzrlib/transport/http/_pycurl.py	2010-05-31 21:31:18 +0000
+++ b/bzrlib/transport/http/_pycurl.py	2010-06-01 13:01:20 +0000
@@ -128,6 +128,11 @@
             self._set_connection(connection, auth)
         return connection
 
+    def disconnect(self):
+        connection = self._get_connection()
+        if connection is not None:
+            connection.close()
+
     def has(self, relpath):
         """See Transport.has()"""
         # We set NO BODY=0 in _get_full, so it should be safe

=== modified file 'bzrlib/transport/http/_urllib.py'
--- a/bzrlib/transport/http/_urllib.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/transport/http/_urllib.py	2010-06-01 13:01:20 +0000
@@ -99,6 +99,11 @@
 
         return response
 
+    def disconnect(self):
+        connection = self._get_connection()
+        if connection is not None:
+            connection.close()
+
     def _get(self, relpath, offsets, tail_amount=0):
         """See HttpTransport._get"""
         abspath = self._remote_path(relpath)

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2010-02-09 20:28:26 +0000
+++ b/bzrlib/transport/remote.py	2010-06-01 13:01:20 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -435,7 +435,9 @@
         remote._translate_error(err, path=relpath)
 
     def disconnect(self):
-        self.get_smart_medium().disconnect()
+        m = self.get_smart_medium()
+        if m is not None:
+            m.disconnect()
 
     def stat(self, relpath):
         resp = self._call2('stat', self._remote_path(relpath))

=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py	2010-05-24 01:05:14 +0000
+++ b/bzrlib/transport/sftp.py	2010-06-01 13:01:20 +0000
@@ -389,6 +389,11 @@
                                          self._host, self._port)
         return connection, (user, password)
 
+    def disconnect(self):
+        connection = self._get_connection()
+        if connection is not None:
+            connection.close()
+
     def _get_sftp(self):
         """Ensures that a connection is established"""
         connection = self._get_connection()



More information about the bazaar-commits mailing list