Rev 5273: Fix http redirection socket leaks. in file:///home/vila/src/bzr/experimental/leaking-tests/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jun 15 11:23:11 BST 2010
At file:///home/vila/src/bzr/experimental/leaking-tests/
------------------------------------------------------------
revno: 5273
revision-id: v.ladeuil+lp at free.fr-20100615102311-0mfzcv8290ctbv1t
parent: v.ladeuil+lp at free.fr-20100612151036-10qaf6ufz72ntnnj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: catch-them-all
timestamp: Tue 2010-06-15 12:23:11 +0200
message:
Fix http redirection socket leaks.
* bzrlib/tests/test_http.py:
(cleanup_http_redirection_connections): Redirected http
connections are not captured by the urllib implementation, they
need to be cleaned up.
(TestHTTPSilentRedirections.setUp)
(TestDoCatchRedirections.setUp, TestAuthOnRedirected.setUp):
Capture the redirected connections to clean them up.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_http.py'
--- a/bzrlib/tests/test_http.py 2010-06-12 14:56:23 +0000
+++ b/bzrlib/tests/test_http.py 2010-06-15 10:23:11 +0000
@@ -1337,6 +1337,27 @@
test.overrideAttr(_urllib2_wrappers, 'Request', RedirectedRequest)
+def cleanup_http_redirection_connections(test):
+ # Some sockets are opened but never seen by _urllib, so we trap them at
+ # the _urllib2_wrappers level to be able to clean them up.
+ def socket_disconnect(sock):
+ try:
+ sock.shutdown(socket.SHUT_RDWR)
+ sock.close()
+ except socket.error:
+ pass
+ def connect(connection):
+ test.http_connect_orig(connection)
+ test.addCleanup(socket_disconnect, connection.sock)
+ test.http_connect_orig = test.overrideAttr(
+ _urllib2_wrappers.HTTPConnection, 'connect', connect)
+ def connect(connection):
+ test.https_connect_orig(connection)
+ test.addCleanup(socket_disconnect, connection.sock)
+ test.https_connect_orig = test.overrideAttr(
+ _urllib2_wrappers.HTTPSConnection, 'connect', connect)
+
+
class TestHTTPSilentRedirections(http_utils.TestCaseWithRedirectedWebserver):
"""Test redirections.
@@ -1358,6 +1379,7 @@
"pycurl doesn't redirect silently anymore")
super(TestHTTPSilentRedirections, self).setUp()
install_redirected_request(self)
+ cleanup_http_redirection_connections(self)
self.build_tree_contents([('a','a'),
('1/',),
('1/a', 'redirected once'),
@@ -1403,6 +1425,7 @@
def setUp(self):
super(TestDoCatchRedirections, self).setUp()
self.build_tree_contents([('a', '0123456789'),],)
+ cleanup_http_redirection_connections(self)
self.old_transport = self.get_old_transport()
@@ -2106,6 +2129,7 @@
('(.*)', r'%s/1\1' % (new_prefix), 301),]
self.old_transport = self.get_old_transport()
self.new_server.add_user('joe', 'foo')
+ cleanup_http_redirection_connections(self)
def create_transport_readonly_server(self):
server = self._auth_server(protocol_version=self._protocol_version)
More information about the bazaar-commits
mailing list