~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_serve.py

  • Committer: Jelmer Vernooij
  • Date: 2009-01-28 18:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3968.
  • Revision ID: jelmer@samba.org-20090128184255-bdmklkvm83ltk191
Update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import signal
22
22
import subprocess
 
23
import sys
23
24
import threading
24
25
 
25
 
from bzrlib import errors
 
26
from bzrlib import (
 
27
    errors,
 
28
    osutils,
 
29
    revision as _mod_revision,
 
30
    )
26
31
from bzrlib.branch import Branch
27
32
from bzrlib.bzrdir import BzrDir
28
33
from bzrlib.errors import ParamikoNotPresent
 
34
from bzrlib.smart import medium
29
35
from bzrlib.tests import TestCaseWithTransport, TestSkipped
30
 
from bzrlib.transport import get_transport, smart
 
36
from bzrlib.transport import get_transport, remote
31
37
 
32
38
 
33
39
class TestBzrServe(TestCaseWithTransport):
39
45
        process.stdin.close()
40
46
        # Hide stdin from the subprocess module, so it won't fail to close it.
41
47
        process.stdin = None
42
 
        result = self.finish_bzr_subprocess(process, retcode=0)
 
48
        result = self.finish_bzr_subprocess(process)
43
49
        self.assertEqual('', result[0])
44
50
        self.assertEqual('', result[1])
45
51
    
51
57
        self.assertEqual('', result[0])
52
58
        self.assertEqual('bzr: interrupted\n', result[1])
53
59
 
 
60
    def make_read_requests(self, branch):
 
61
        """Do some read only requests."""
 
62
        branch.lock_read()
 
63
        try:
 
64
            branch.repository.all_revision_ids()
 
65
            self.assertEqual(_mod_revision.NULL_REVISION,
 
66
                             _mod_revision.ensure_null(branch.last_revision()))
 
67
        finally:
 
68
            branch.unlock()
 
69
 
54
70
    def start_server_inet(self, extra_options=()):
55
71
        """Start a bzr server subprocess using the --inet option.
56
72
 
64
80
        # Connect to the server
65
81
        # We use this url because while this is no valid URL to connect to this
66
82
        # server instance, the transport needs a URL.
67
 
        medium = smart.SmartSimplePipesClientMedium(
68
 
            process.stdout, process.stdin)
69
 
        transport = smart.SmartTransport('bzr://localhost/', medium=medium)
 
83
        url = 'bzr://localhost/'
 
84
        client_medium = medium.SmartSimplePipesClientMedium(
 
85
            process.stdout, process.stdin, url)
 
86
        transport = remote.RemoteTransport(url, medium=client_medium)
70
87
        return process, transport
71
88
 
72
89
    def start_server_port(self, extra_options=()):
80
97
        args = ['serve', '--port', 'localhost:0']
81
98
        args.extend(extra_options)
82
99
        process = self.start_bzr_subprocess(args, skip_if_plan_to_signal=True)
83
 
        port_line = process.stdout.readline()
 
100
        port_line = process.stderr.readline()
84
101
        prefix = 'listening on port: '
85
102
        self.assertStartsWith(port_line, prefix)
86
103
        port = int(port_line[len(prefix):])
100
117
 
101
118
        # We get a working branch
102
119
        branch = BzrDir.open_from_transport(transport).open_branch()
103
 
        branch.repository.get_revision_graph()
104
 
        self.assertEqual(None, branch.last_revision())
 
120
        self.make_read_requests(branch)
105
121
        self.assertInetServerShutsdownCleanly(process)
106
122
 
107
123
    def test_bzr_serve_port_readonly(self):
119
135
 
120
136
        # Connect to the server
121
137
        branch = Branch.open(url)
122
 
 
123
 
        # We get a working branch
124
 
        branch.repository.get_revision_graph()
125
 
        self.assertEqual(None, branch.last_revision())
126
 
 
 
138
        self.make_read_requests(branch)
127
139
        self.assertServerFinishesCleanly(process)
128
140
 
129
 
    def test_bzr_serve_no_args(self):
130
 
        """'bzr serve' with no arguments or options should not traceback."""
131
 
        out, err = self.run_bzr_error(
132
 
            ['bzr serve requires one of --inet or --port'], 'serve')
133
 
 
134
141
    def test_bzr_connect_to_bzr_ssh(self):
135
142
        """User acceptance that get_transport of a bzr+ssh:// behaves correctly.
136
143
 
192
199
 
193
200
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
194
201
        # variable is used to tell bzr what command to run on the remote end.
195
 
        path_to_branch = os.path.abspath('a_branch')
 
202
        path_to_branch = osutils.abspath('a_branch')
196
203
        
197
204
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
198
 
        os.environ['BZR_REMOTE_PATH'] = self.get_bzr_path()
 
205
        bzr_remote_path = self.get_bzr_path()
 
206
        if sys.platform == 'win32':
 
207
            bzr_remote_path = sys.executable + ' ' + self.get_bzr_path()
 
208
        os.environ['BZR_REMOTE_PATH'] = bzr_remote_path
199
209
        try:
 
210
            if sys.platform == 'win32':
 
211
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
200
212
            branch = Branch.open(
201
213
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
202
 
            
203
 
            branch.repository.get_revision_graph()
204
 
            self.assertEqual(None, branch.last_revision())
 
214
            self.make_read_requests(branch)
205
215
            # Check we can perform write operations
206
216
            branch.bzrdir.root_transport.mkdir('foo')
207
217
        finally:
214
224
 
215
225
        self.assertEqual(
216
226
            ['%s serve --inet --directory=/ --allow-writes'
217
 
             % self.get_bzr_path()],
 
227
             % bzr_remote_path],
218
228
            self.command_executed)
219
229