/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Tests of the bzr serve command."""
48
48
        result = self.finish_bzr_subprocess(process)
49
49
        self.assertEqual('', result[0])
50
50
        self.assertEqual('', result[1])
51
 
    
 
51
 
52
52
    def assertServerFinishesCleanly(self, process):
53
53
        """Shutdown the bzr serve instance process looking for errors."""
54
54
        # Shutdown the server
57
57
        self.assertEqual('', result[0])
58
58
        self.assertEqual('bzr: interrupted\n', result[1])
59
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
 
60
70
    def start_server_inet(self, extra_options=()):
61
71
        """Start a bzr server subprocess using the --inet option.
62
72
 
70
80
        # Connect to the server
71
81
        # We use this url because while this is no valid URL to connect to this
72
82
        # server instance, the transport needs a URL.
 
83
        url = 'bzr://localhost/'
73
84
        client_medium = medium.SmartSimplePipesClientMedium(
74
 
            process.stdout, process.stdin)
75
 
        transport = remote.RemoteTransport(
76
 
            'bzr://localhost/', medium=client_medium)
 
85
            process.stdout, process.stdin, url)
 
86
        transport = remote.RemoteTransport(url, medium=client_medium)
77
87
        return process, transport
78
88
 
79
89
    def start_server_port(self, extra_options=()):
87
97
        args = ['serve', '--port', 'localhost:0']
88
98
        args.extend(extra_options)
89
99
        process = self.start_bzr_subprocess(args, skip_if_plan_to_signal=True)
90
 
        port_line = process.stdout.readline()
 
100
        port_line = process.stderr.readline()
91
101
        prefix = 'listening on port: '
92
102
        self.assertStartsWith(port_line, prefix)
93
103
        port = int(port_line[len(prefix):])
107
117
 
108
118
        # We get a working branch
109
119
        branch = BzrDir.open_from_transport(transport).open_branch()
110
 
        branch.repository.get_revision_graph()
111
 
        self.assertEqual(_mod_revision.NULL_REVISION,
112
 
                         _mod_revision.ensure_null(branch.last_revision()))
 
120
        self.make_read_requests(branch)
113
121
        self.assertInetServerShutsdownCleanly(process)
114
122
 
115
123
    def test_bzr_serve_port_readonly(self):
127
135
 
128
136
        # Connect to the server
129
137
        branch = Branch.open(url)
130
 
 
131
 
        # We get a working branch
132
 
        branch.repository.get_revision_graph()
133
 
        self.assertEqual(_mod_revision.NULL_REVISION,
134
 
                         _mod_revision.ensure_null(branch.last_revision()))
135
 
 
 
138
        self.make_read_requests(branch)
136
139
        self.assertServerFinishesCleanly(process)
137
140
 
138
141
    def test_bzr_connect_to_bzr_ssh(self):
145
148
        except ParamikoNotPresent:
146
149
            raise TestSkipped('Paramiko not installed')
147
150
        from bzrlib.tests.stub_sftp import StubServer
148
 
        
 
151
 
149
152
        # Make a branch
150
153
        self.make_branch('a_branch')
151
154
 
164
167
                proc = subprocess.Popen(
165
168
                    command, shell=True, stdin=subprocess.PIPE,
166
169
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
167
 
                
 
170
 
168
171
                # XXX: horribly inefficient, not to mention ugly.
169
172
                # Start a thread for each of stdin/out/err, and relay bytes from
170
173
                # the subprocess to channel and vice versa.
197
200
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
198
201
        # variable is used to tell bzr what command to run on the remote end.
199
202
        path_to_branch = osutils.abspath('a_branch')
200
 
        
 
203
 
201
204
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
202
205
        bzr_remote_path = self.get_bzr_path()
203
206
        if sys.platform == 'win32':
208
211
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
209
212
            branch = Branch.open(
210
213
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
211
 
            
212
 
            branch.repository.get_revision_graph()
213
 
            self.assertEqual(_mod_revision.NULL_REVISION,
214
 
                             _mod_revision.ensure_null(branch.last_revision()))
 
214
            self.make_read_requests(branch)
215
215
            # Check we can perform write operations
216
216
            branch.bzrdir.root_transport.mkdir('foo')
217
217
        finally:
226
226
            ['%s serve --inet --directory=/ --allow-writes'
227
227
             % bzr_remote_path],
228
228
            self.command_executed)
229
 
        
 
229