45
45
from bzrlib.trace import mutter
46
46
from bzrlib.transport import get_transport, remote
49
class TestBzrServe(TestCaseWithTransport):
48
class TestBzrServeBase(TestCaseWithTransport):
50
def run_bzr_serve_then_func(self, serve_args, retcode=0, func=None,
51
*func_args, **func_kwargs):
52
"""Run 'bzr serve', and run the given func in a thread once the server
55
When 'func' terminates, the server will be terminated too.
57
Returns stdout and stderr.
60
def on_server_start(backing_urls, tcp_server):
62
target=on_server_start_thread, args=(tcp_server,))
64
def on_server_start_thread(tcp_server):
67
self.tcp_server = tcp_server
70
func(*func_args, **func_kwargs)
72
# Log errors to make some test failures a little less
74
mutter('func broke: %r', e)
76
# Then stop the server
77
mutter('interrupting...')
78
thread.interrupt_main()
79
SmartTCPServer.hooks.install_named_hook(
80
'server_started_ex', on_server_start,
81
'run_bzr_serve_then_func hook')
84
out, err = self.run_bzr(['serve'] + list(serve_args))
85
except KeyboardInterrupt, e:
90
class TestBzrServe(TestBzrServeBase):
52
93
super(TestBzrServe, self).setUp()
119
160
url = 'bzr://localhost:%d/' % port
120
161
self.permit_url(url)
121
162
return process, url
164
def test_bzr_serve_quiet(self):
165
self.make_branch('.')
166
args = ['--port', 'localhost:0', '--quiet']
167
out, err = self.run_bzr_serve_then_func(args, retcode=3)
168
self.assertEqual('', out)
169
self.assertEqual('', err)
123
171
def test_bzr_serve_inet_readonly(self):
124
172
"""bzr server should provide a read only filesystem by default."""
168
216
self.assertServerFinishesCleanly(process)
171
class TestCmdServeChrooting(TestCaseWithTransport):
219
class TestCmdServeChrooting(TestBzrServeBase):
173
221
def test_serve_tcp(self):
174
222
"""'bzr serve' wraps the given --directory in a ChrootServer.
183
231
['--port', '127.0.0.1:0',
184
232
'--directory', t.local_abspath('server-root'),
185
233
'--allow-writes'],
186
self.when_server_started)
234
func=self.when_server_started)
187
235
# The when_server_started method issued a find_repositoryV3 that should
188
236
# fail with 'norepository' because there are no repositories inside the
190
238
self.assertEqual(('norepository',), self.client_resp)
192
def run_bzr_serve_then_func(self, serve_args, func, *func_args,
194
"""Run 'bzr serve', and run the given func in a thread once the server
197
When 'func' terminates, the server will be terminated too.
200
def on_server_start(backing_urls, tcp_server):
201
t = threading.Thread(
202
target=on_server_start_thread, args=(tcp_server,))
204
def on_server_start_thread(tcp_server):
207
self.tcp_server = tcp_server
209
func(*func_args, **func_kwargs)
211
# Log errors to make some test failures a little less
213
mutter('func broke: %r', e)
215
# Then stop the server
216
mutter('interrupting...')
217
thread.interrupt_main()
218
SmartTCPServer.hooks.install_named_hook(
219
'server_started_ex', on_server_start,
220
'run_bzr_serve_then_func hook')
223
self.run_bzr(['serve'] + list(serve_args))
224
except KeyboardInterrupt:
227
240
def when_server_started(self):
228
241
# Connect to the TCP server and issue some requests and see what comes