Rev 2519: Refactor mutiple connections detection and fix false positives. Only in file:///v/home/vila/src/experimental/reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sun Jun 3 16:52:22 BST 2007
At file:///v/home/vila/src/experimental/reuse.transports/
------------------------------------------------------------
revno: 2519
revision-id: v.ladeuil+lp at free.fr-20070603155219-f7dtbnwdqrhs0kpk
parent: v.ladeuil+lp at free.fr-20070603130158-kfeitm6gxuxt0b1j
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Sun 2007-06-03 17:52:19 +0200
message:
Refactor mutiple connections detection and fix false positives. Only
merge and pull are still bougs.
* bzrlib/tests/commands/test_push.py:
(TestPush.test_push): Reset connections after branch and tree
creation.
* bzrlib/tests/commands/test_missing.py:
(TestMissing.test_missing): Reset connections after branch and tree
creation.
* bzrlib/tests/commands/test_merge.py:
(TestMerge.test_merge): Reset connections after branch and tree
creation.
* bzrlib/tests/commands/test_checkout.py:
(TestCheckout.test_checkout): Reset connections after branch and tree
creation.
* bzrlib/tests/commands/test_cat.py:
(TestCat.test_cat): Reset connections after branch and tree
creation.
* bzrlib/tests/commands/test_branch.py:
(TestBranch.setUp): Reset connections after branch and tree
creation.
* bzrlib/tests/TransportUtil.py:
(TransportHooks.__init__): Use _set_connection instead of
_get_FTP.
(ConnectionHookedTransport): Replace _get_FTP by _set_connection.
(TestCaseWithConnectionHookedTransport.setUp): Replace _get_FTP by
_set_connection.
(TestCaseWithConnectionHookedTransport.reset_connections): New
method.
(TestCaseWithConnectionHookedTransport.set_connection_hook):
Replace get_connection_hook.
modified:
bzrlib/tests/TransportUtil.py transportutil.py-20070525113600-5v2igk89s8fensom-1
bzrlib/tests/commands/test_branch.py test_branch.py-20070520173042-ou3a796w3xn1y8ps-1
bzrlib/tests/commands/test_cat.py test_cat.py-20070525170351-vg2apsfb5j413913-1
bzrlib/tests/commands/test_checkout.py test_checkout.py-20070525151718-vm7ligd5px5dtmda-1
bzrlib/tests/commands/test_merge.py test_merge.py-20070525163813-v8yfs5wu77hjsx0o-1
bzrlib/tests/commands/test_missing.py test_missing.py-20070525171057-qr1z4sleurlp9b5v-1
bzrlib/tests/commands/test_pull.py test_pull.py-20070525144918-cgmunk4ici2krjnd-1
bzrlib/tests/commands/test_push.py test_push.py-20070525122003-gc1ob0ea0nueoqgj-1
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
-------------- next part --------------
=== modified file 'bzrlib/tests/TransportUtil.py'
--- a/bzrlib/tests/TransportUtil.py 2007-05-25 11:38:40 +0000
+++ b/bzrlib/tests/TransportUtil.py 2007-06-03 15:52:19 +0000
@@ -29,9 +29,9 @@
def __init__(self):
Hooks.__init__(self)
- # invoked when the transport is about to create or reuse
- # an ftp connection. The api signature is (transport, ftp_instance)
- self['get_FTP'] = []
+ # Invoked when the transport has just created a new connection.
+ # The api signature is (transport, connection, credentials)
+ self['_set_connection'] = []
class InstrumentedTransport(FtpTransport):
@@ -43,25 +43,20 @@
class ConnectionHookedTransport(InstrumentedTransport):
"""Transport instrumented to inspect connections"""
- def _get_FTP(self):
- """See FtpTransport._get_FTP.
-
- This is where we can detect if the connection is reused
- or if a new one is created. This a bit ugly, but it's the
- easiest until transport classes are refactored.
- """
- instance = super(ConnectionHookedTransport, self)._get_FTP()
- for hook in self.hooks['get_FTP']:
- hook(self, instance)
- return instance
+ def _set_connection(self, connection, credentials):
+ """Called when a new connection is created """
+ super(ConnectionHookedTransport, self)._set_connection(connection,
+ credentials)
+ for hook in self.hooks['_set_connection']:
+ hook(self, connection, credentials)
class TestCaseWithConnectionHookedTransport(TestCaseWithFTPServer):
def setUp(self):
super(TestCaseWithConnectionHookedTransport, self).setUp()
- ConnectionHookedTransport.hooks.install_hook('get_FTP',
- self.get_connection_hook)
+ ConnectionHookedTransport.hooks.install_hook('_set_connection',
+ self.set_connection_hook)
# Make our instrumented transport the default ftp transport
register_transport('ftp://', ConnectionHookedTransport)
@@ -72,7 +67,9 @@
self.addCleanup(cleanup)
self.connections = []
- def get_connection_hook(self, transport, connection):
- if connection is not None and connection not in self.connections:
- self.connections.append(connection)
+ def reset_connections(self):
+ self.connections = []
+
+ def set_connection_hook(self, transport, connection, credentials):
+ self.connections.append(connection)
=== modified file 'bzrlib/tests/commands/test_branch.py'
--- a/bzrlib/tests/commands/test_branch.py 2007-05-25 15:11:05 +0000
+++ b/bzrlib/tests/commands/test_branch.py 2007-06-03 15:52:19 +0000
@@ -21,22 +21,25 @@
class TestBranch(TestCaseWithConnectionHookedTransport):
+ def setUp(self):
+ super(TestBranch, self).setUp()
+ self.make_branch_and_tree('branch')
+ # make_branch_and_tree create one connection
+ self.reset_connections()
+
def test_branch_remote_local(self):
- self.make_branch_and_tree('branch')
cmd = cmd_branch()
cmd.run(self.get_url() + '/branch', 'local')
self.assertEquals(1, len(self.connections))
# This is bug 112173
def test_branch_local_remote(self):
- self.make_branch_and_tree('branch')
cmd = cmd_branch()
cmd.run('branch', self.get_url() + '/remote')
self.assertEquals(1, len(self.connections))
# This is bug 112173 too
def test_branch_remote_remote(self):
- self.make_branch_and_tree('branch')
cmd = cmd_branch()
cmd.run(self.get_url() + '/branch', self.get_url() + '/remote')
self.assertEquals(2, len(self.connections))
=== modified file 'bzrlib/tests/commands/test_cat.py'
--- a/bzrlib/tests/commands/test_cat.py 2007-05-25 17:47:10 +0000
+++ b/bzrlib/tests/commands/test_cat.py 2007-06-03 15:52:19 +0000
@@ -36,6 +36,8 @@
def test_cat(self):
wt1 = self.make_branch_and_tree('branch')
+ # make_branch_and_tree create one connection
+ self.reset_connections()
file('branch/foo', 'wb').write('foo')
wt1.add('foo')
wt1.commit('add foo')
=== modified file 'bzrlib/tests/commands/test_checkout.py'
--- a/bzrlib/tests/commands/test_checkout.py 2007-05-25 16:39:29 +0000
+++ b/bzrlib/tests/commands/test_checkout.py 2007-06-03 15:52:19 +0000
@@ -22,6 +22,8 @@
def test_checkout(self):
self.make_branch_and_tree('branch1')
+ # make_branch_and_tree create one connection
+ self.reset_connections()
cmd = cmd_checkout()
cmd.run(self.get_url() + '/branch1', 'local')
=== modified file 'bzrlib/tests/commands/test_merge.py'
--- a/bzrlib/tests/commands/test_merge.py 2007-05-25 16:39:29 +0000
+++ b/bzrlib/tests/commands/test_merge.py 2007-06-03 15:52:19 +0000
@@ -27,6 +27,8 @@
wt2 = self.make_branch_and_tree('branch2')
wt2.pull(wt1.branch)
wt2.commit('empty commit too')
+ # make_branch_and_tree calls have created connections
+ self.reset_connections()
cmd = cmd_merge()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_missing.py'
--- a/bzrlib/tests/commands/test_missing.py 2007-05-25 17:12:52 +0000
+++ b/bzrlib/tests/commands/test_missing.py 2007-06-03 15:52:19 +0000
@@ -27,6 +27,8 @@
wt2 = self.make_branch_and_tree('branch2')
wt2.pull(wt1.branch)
wt2.commit('empty commit too')
+ # make_branch_and_tree calls have created connections
+ self.reset_connections()
cmd = cmd_missing()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_pull.py'
--- a/bzrlib/tests/commands/test_pull.py 2007-05-25 15:11:05 +0000
+++ b/bzrlib/tests/commands/test_pull.py 2007-06-03 15:52:19 +0000
@@ -25,6 +25,8 @@
wt1 = self.make_branch_and_tree('branch1')
tip = wt1.commit('empty commit')
wt2 = self.make_branch_and_tree('branch2')
+ # make_branch_and_tree calls have created connections
+ self.reset_connections()
cmd = cmd_pull()
# We don't care about the ouput but 'outf' should be defined
=== modified file 'bzrlib/tests/commands/test_push.py'
--- a/bzrlib/tests/commands/test_push.py 2007-05-25 14:41:42 +0000
+++ b/bzrlib/tests/commands/test_push.py 2007-06-03 15:52:19 +0000
@@ -22,6 +22,8 @@
def test_push(self):
self.make_branch_and_tree('branch')
+ # make_branch_and_tree create one connection
+ self.reset_connections()
cmd = cmd_push()
cmd.run(self.get_url() + '/remote', directory='branch')
self.assertEquals(1, len(self.connections))
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py 2007-06-03 12:58:49 +0000
+++ b/bzrlib/transport/__init__.py 2007-06-03 15:52:19 +0000
@@ -1212,11 +1212,12 @@
self._connection = [(None, None)]
def _set_connection(self, connection, credentials=None):
- """Set the transport specific connection object.
+ """Record a newly created connection with its associated credentials.
Note: To ensure that connection is still shared after a temporary
failure and a new one needs to be created, daughter classes should
- always call this method to set the connection.
+ always call this method to set the connection and do so each time a new
+ connection is created.
:param connection: An opaque object representing the connection used by
the daughter class.
@@ -1237,7 +1238,7 @@
return self._connection[0][0]
def _get_credentials(self):
- """Returns the credentials needed to establish a connection."""
+ """Returns the credentials used to establish the connection."""
(connection, credentials) = self._connection[0]
return self._connection[0][1]
More information about the bazaar-commits
mailing list