~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-10-14 08:51:07 UTC
  • mto: (2080.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2081.
  • Revision ID: bialix@ukr.net-20061014085107-8dff865674eed30a
win32 installer: make short info page instead of full GPL license text

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
import os
21
21
import signal
22
22
import subprocess
23
 
import sys
24
23
import threading
25
24
 
26
 
from bzrlib import (
27
 
    errors,
28
 
    osutils,
29
 
    revision as _mod_revision,
30
 
    )
 
25
from bzrlib import errors
31
26
from bzrlib.branch import Branch
32
27
from bzrlib.bzrdir import BzrDir
33
28
from bzrlib.errors import ParamikoNotPresent
34
 
from bzrlib.smart import medium
35
29
from bzrlib.tests import TestCaseWithTransport, TestSkipped
36
 
from bzrlib.transport import get_transport, remote
 
30
from bzrlib.transport import get_transport, smart
 
31
 
 
32
 
 
33
class DoesNotCloseStdOutClient(smart.SmartStreamClient):
 
34
    """A client that doesn't close stdout upon disconnect().
 
35
    
 
36
    We wish to let stdout remain open so that we can see if the server writes
 
37
    anything to stdout during its shutdown.
 
38
    """
 
39
 
 
40
    def disconnect(self):
 
41
        if self._connected:
 
42
            self._connected = False
 
43
            # The client's out is the server's in.
 
44
            self._out.close()
37
45
 
38
46
 
39
47
class TestBzrServe(TestCaseWithTransport):
40
48
 
41
 
    def assertInetServerShutsdownCleanly(self, process):
 
49
    def assertInetServerShutsdownCleanly(self, client, process):
42
50
        """Shutdown the server process looking for errors."""
43
 
        # Shutdown the server: the server should shut down when it cannot read
44
 
        # from stdin anymore.
45
 
        process.stdin.close()
 
51
        # Disconnect the client forcefully JUST IN CASE because of __del__'s use
 
52
        # in the smart module.
 
53
        client.disconnect()
 
54
 
 
55
        # Shutdown the server: the client should have disconnected cleanly and
 
56
        # closed stdin, so the server process should shut itself down.
 
57
        self.assertTrue(process.stdin.closed)
46
58
        # Hide stdin from the subprocess module, so it won't fail to close it.
47
59
        process.stdin = None
48
 
        result = self.finish_bzr_subprocess(process)
 
60
        result = self.finish_bzr_subprocess(process, retcode=0)
49
61
        self.assertEqual('', result[0])
50
62
        self.assertEqual('', result[1])
51
63
    
70
82
        # Connect to the server
71
83
        # We use this url because while this is no valid URL to connect to this
72
84
        # server instance, the transport needs a URL.
73
 
        client_medium = medium.SmartSimplePipesClientMedium(
74
 
            process.stdout, process.stdin)
75
 
        transport = remote.RemoteTransport(
76
 
            'bzr://localhost/', medium=client_medium)
77
 
        return process, transport
 
85
        client = DoesNotCloseStdOutClient(
 
86
            lambda: (process.stdout, process.stdin))
 
87
        transport = smart.SmartTransport('bzr://localhost/', client=client)
 
88
        return process, client, transport
78
89
 
79
90
    def start_server_port(self, extra_options=()):
80
91
        """Start a bzr server subprocess.
95
106
 
96
107
    def test_bzr_serve_inet_readonly(self):
97
108
        """bzr server should provide a read only filesystem by default."""
98
 
        process, transport = self.start_server_inet()
 
109
        process, client, transport = self.start_server_inet()
99
110
        self.assertRaises(errors.TransportNotPossible, transport.mkdir, 'adir')
100
 
        self.assertInetServerShutsdownCleanly(process)
 
111
        # finish with the transport
 
112
        del transport
 
113
        self.assertInetServerShutsdownCleanly(client, process)
101
114
 
102
115
    def test_bzr_serve_inet_readwrite(self):
103
116
        # Make a branch
104
117
        self.make_branch('.')
105
118
 
106
 
        process, transport = self.start_server_inet(['--allow-writes'])
 
119
        process, client, transport = self.start_server_inet(['--allow-writes'])
107
120
 
108
121
        # We get a working branch
109
122
        branch = BzrDir.open_from_transport(transport).open_branch()
110
123
        branch.repository.get_revision_graph()
111
 
        self.assertEqual(_mod_revision.NULL_REVISION,
112
 
                         _mod_revision.ensure_null(branch.last_revision()))
113
 
        self.assertInetServerShutsdownCleanly(process)
 
124
        self.assertEqual(None, branch.last_revision())
 
125
 
 
126
        # finish with the transport
 
127
        del transport
 
128
 
 
129
        self.assertInetServerShutsdownCleanly(client, process)
114
130
 
115
131
    def test_bzr_serve_port_readonly(self):
116
132
        """bzr server should provide a read only filesystem by default."""
130
146
 
131
147
        # We get a working branch
132
148
        branch.repository.get_revision_graph()
133
 
        self.assertEqual(_mod_revision.NULL_REVISION,
134
 
                         _mod_revision.ensure_null(branch.last_revision()))
 
149
        self.assertEqual(None, branch.last_revision())
135
150
 
136
151
        self.assertServerFinishesCleanly(process)
137
152
 
 
153
    def test_bzr_serve_no_args(self):
 
154
        """'bzr serve' with no arguments or options should not traceback."""
 
155
        out, err = self.run_bzr_error(
 
156
            ['bzr serve requires one of --inet or --port'], 'serve')
 
157
 
138
158
    def test_bzr_connect_to_bzr_ssh(self):
139
159
        """User acceptance that get_transport of a bzr+ssh:// behaves correctly.
140
160
 
196
216
 
197
217
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
198
218
        # variable is used to tell bzr what command to run on the remote end.
199
 
        path_to_branch = osutils.abspath('a_branch')
 
219
        path_to_branch = os.path.abspath('a_branch')
200
220
        
201
221
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
202
 
        bzr_remote_path = self.get_bzr_path()
203
 
        if sys.platform == 'win32':
204
 
            bzr_remote_path = sys.executable + ' ' + self.get_bzr_path()
205
 
        os.environ['BZR_REMOTE_PATH'] = bzr_remote_path
 
222
        os.environ['BZR_REMOTE_PATH'] = self.get_bzr_path()
206
223
        try:
207
 
            if sys.platform == 'win32':
208
 
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
209
224
            branch = Branch.open(
210
225
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
211
226
            
212
227
            branch.repository.get_revision_graph()
213
 
            self.assertEqual(_mod_revision.NULL_REVISION,
214
 
                             _mod_revision.ensure_null(branch.last_revision()))
 
228
            self.assertEqual(None, branch.last_revision())
215
229
            # Check we can perform write operations
216
230
            branch.bzrdir.root_transport.mkdir('foo')
217
231
        finally:
224
238
 
225
239
        self.assertEqual(
226
240
            ['%s serve --inet --directory=/ --allow-writes'
227
 
             % bzr_remote_path],
 
241
             % self.get_bzr_path()],
228
242
            self.command_executed)
229
243