~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import os
19
 
import socket
 
19
import SocketServer
20
20
import sys
21
 
import threading
22
21
 
23
22
from bzrlib import (
24
23
    bzrdir,
28
27
    merge,
29
28
    osutils,
30
29
    revision as _mod_revision,
31
 
    symbol_versioning,
32
30
    tests,
33
31
    treebuilder,
34
32
    )
42
40
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
43
41
from bzrlib.repofmt import knitrepo
44
42
from bzrlib.tests import (
 
43
    features,
 
44
    test_commit,
45
45
    test_read_bundle,
46
 
    test_commit,
 
46
    test_server,
47
47
    )
48
48
from bzrlib.transform import TreeTransform
49
 
from bzrlib.tests import (
50
 
    features,
51
 
    )
52
49
 
53
50
 
54
51
def get_text(vf, key):
510
507
                new.unlock()
511
508
                old.unlock()
512
509
        if not _mod_revision.is_null(rev_id):
513
 
            rh = self.b1.revision_history()
514
 
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
515
 
                tree.branch.set_revision_history, rh[:rh.index(rev_id)+1])
 
510
            tree.branch.generate_revision_history(rev_id)
516
511
            tree.update()
517
512
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
518
513
            self.assertFalse(delta.has_changed(),
1423
1418
            from bzrlib.testament import Testament
1424
1419
            # monkey patch gpg signing mechanism
1425
1420
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
1426
 
            new_config = test_commit.MustSignConfig(branch)
1427
 
            commit.Commit(config=new_config).commit(message="base",
 
1421
            new_config = test_commit.MustSignConfig()
 
1422
            commit.Commit(config_stack=new_config).commit(message="base",
1428
1423
                                                    allow_pointless=True,
1429
1424
                                                    rev_id='B',
1430
1425
                                                    working_tree=tree_a)
1839
1834
        bundle, then the ConnectionReset error should be propagated.
1840
1835
        """
1841
1836
        # Instantiate a server that will provoke a ConnectionReset
1842
 
        sock_server = _DisconnectingTCPServer()
 
1837
        sock_server = DisconnectingServer()
1843
1838
        self.start_server(sock_server)
1844
1839
        # We don't really care what the url is since the server will close the
1845
1840
        # connection without interpreting it
1847
1842
        self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1848
1843
 
1849
1844
 
1850
 
class _DisconnectingTCPServer(object):
1851
 
    """A TCP server that immediately closes any connection made to it."""
1852
 
 
1853
 
    def start_server(self):
1854
 
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1855
 
        self.sock.bind(('127.0.0.1', 0))
1856
 
        self.sock.listen(1)
1857
 
        self.port = self.sock.getsockname()[1]
1858
 
        self.thread = threading.Thread(
1859
 
            name='%s (port %d)' % (self.__class__.__name__, self.port),
1860
 
            target=self.accept_and_close)
1861
 
        self.thread.start()
1862
 
 
1863
 
    def accept_and_close(self):
1864
 
        conn, addr = self.sock.accept()
1865
 
        conn.shutdown(socket.SHUT_RDWR)
1866
 
        conn.close()
 
1845
class DisconnectingHandler(SocketServer.BaseRequestHandler):
 
1846
    """A request handler that immediately closes any connection made to it."""
 
1847
 
 
1848
    def handle(self):
 
1849
        self.request.close()
 
1850
 
 
1851
 
 
1852
class DisconnectingServer(test_server.TestingTCPServerInAThread):
 
1853
 
 
1854
    def __init__(self):
 
1855
        super(DisconnectingServer, self).__init__(
 
1856
            ('127.0.0.1', 0),
 
1857
            test_server.TestingTCPServer,
 
1858
            DisconnectingHandler)
1867
1859
 
1868
1860
    def get_url(self):
1869
 
        return 'bzr://127.0.0.1:%d/' % (self.port,)
1870
 
 
1871
 
    def stop_server(self):
1872
 
        try:
1873
 
            # make sure the thread dies by connecting to the listening socket,
1874
 
            # just in case the test failed to do so.
1875
 
            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1876
 
            conn.connect(self.sock.getsockname())
1877
 
            conn.close()
1878
 
        except socket.error:
1879
 
            pass
1880
 
        self.sock.close()
1881
 
        self.thread.join()
 
1861
        """Return the url of the server"""
 
1862
        return "bzr://%s:%d/" % self.server.server_address