/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 breezy/tests/test_server.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from bzrlib import (
 
17
import errno
 
18
import socket
 
19
try:
 
20
    import socketserver
 
21
except ImportError:
 
22
    import SocketServer as socketserver
 
23
import sys
 
24
import threading
 
25
import traceback
 
26
 
 
27
 
 
28
from breezy import (
 
29
    cethread,
 
30
    errors,
 
31
    osutils,
18
32
    transport,
19
33
    urlutils,
20
34
    )
21
 
from bzrlib.transport import (
 
35
from breezy.transport import (
22
36
    chroot,
23
37
    pathfilter,
24
38
    )
25
 
from bzrlib.smart import server
 
39
from breezy.bzr.smart import (
 
40
    medium,
 
41
    server,
 
42
    )
 
43
 
 
44
 
 
45
def debug_threads():
 
46
    # FIXME: There is a dependency loop between breezy.tests and
 
47
    # breezy.tests.test_server that needs to be fixed. In the mean time
 
48
    # defining this function is enough for our needs. -- vila 20100611
 
49
    from breezy import tests
 
50
    return 'threads' in tests.selftest_debug_flags
26
51
 
27
52
 
28
53
class TestServer(transport.Server):
31
56
    The TestServer interface provides a server for a given transport. We use
32
57
    these servers as loopback testing tools. For any given transport the
33
58
    Servers it provides must either allow writing, or serve the contents
34
 
    of os.getcwdu() at the time start_server is called.
 
59
    of osutils.getcwd() at the time start_server is called.
35
60
 
36
61
    Note that these are real servers - they must implement all the things
37
62
    that we want bzr transports to take advantage of.
44
69
        a database like svn, or a memory only transport, it should return
45
70
        a connection to a newly established resource for this Server.
46
71
        Otherwise it should return a url that will provide access to the path
47
 
        that was os.getcwdu() when start_server() was called.
 
72
        that was osutils.getcwd() when start_server() was called.
48
73
 
49
74
        Subsequent calls will return the same resource.
50
75
        """
82
107
    """
83
108
 
84
109
    def start_server(self, server=None):
85
 
        """See bzrlib.transport.Server.start_server.
 
110
        """See breezy.transport.Server.start_server.
86
111
 
87
112
        :server: decorate the urls given by server. If not provided a
88
113
        LocalServer is created.
108
133
        return self.get_decorator_class()._get_url_prefix()
109
134
 
110
135
    def get_bogus_url(self):
111
 
        """See bzrlib.transport.Server.get_bogus_url."""
 
136
        """See breezy.transport.Server.get_bogus_url."""
112
137
        return self.get_url_prefix() + self._server.get_bogus_url()
113
138
 
114
139
    def get_url(self):
115
 
        """See bzrlib.transport.Server.get_url."""
 
140
        """See breezy.transport.Server.get_url."""
116
141
        return self.get_url_prefix() + self._server.get_url()
117
142
 
118
143
 
120
145
    """Server for the BrokenRenameTransportDecorator for testing with."""
121
146
 
122
147
    def get_decorator_class(self):
123
 
        from bzrlib.transport import brokenrename
 
148
        from breezy.transport import brokenrename
124
149
        return brokenrename.BrokenRenameTransportDecorator
125
150
 
126
151
 
128
153
    """Server for the FakeNFSTransportDecorator for testing with."""
129
154
 
130
155
    def get_decorator_class(self):
131
 
        from bzrlib.transport import fakenfs
 
156
        from breezy.transport import fakenfs
132
157
        return fakenfs.FakeNFSTransportDecorator
133
158
 
134
159
 
139
164
    """
140
165
 
141
166
    def get_decorator_class(self):
142
 
        from bzrlib.transport import fakevfat
 
167
        from breezy.transport import fakevfat
143
168
        return fakevfat.FakeVFATTransportDecorator
144
169
 
145
170
 
147
172
    """Server for testing."""
148
173
 
149
174
    def get_decorator_class(self):
150
 
        from bzrlib.transport import log
 
175
        from breezy.transport import log
151
176
        return log.TransportLogDecorator
152
177
 
153
178
 
155
180
    """Server for the NoSmartTransportDecorator for testing with."""
156
181
 
157
182
    def get_decorator_class(self):
158
 
        from bzrlib.transport import nosmart
 
183
        from breezy.transport import nosmart
159
184
        return nosmart.NoSmartTransportDecorator
160
185
 
161
186
 
163
188
    """Server for the ReadonlyTransportDecorator for testing with."""
164
189
 
165
190
    def get_decorator_class(self):
166
 
        from bzrlib.transport import readonly
 
191
        from breezy.transport import readonly
167
192
        return readonly.ReadonlyTransportDecorator
168
193
 
169
194
 
171
196
    """Server for the TransportTraceDecorator for testing with."""
172
197
 
173
198
    def get_decorator_class(self):
174
 
        from bzrlib.transport import trace
 
199
        from breezy.transport import trace
175
200
        return trace.TransportTraceDecorator
176
201
 
177
202
 
179
204
    """Server for the UnlistableTransportDecorator for testing with."""
180
205
 
181
206
    def get_decorator_class(self):
182
 
        from bzrlib.transport import unlistable
 
207
        from breezy.transport import unlistable
183
208
        return unlistable.UnlistableTransportDecorator
184
209
 
185
210
 
192
217
    def start_server(self, backing_server=None):
193
218
        """Setup the Chroot on backing_server."""
194
219
        if backing_server is not None:
195
 
            self.backing_transport = transport.get_transport(
 
220
            self.backing_transport = transport.get_transport_from_url(
196
221
                backing_server.get_url())
197
222
        else:
198
 
            self.backing_transport = transport.get_transport('.')
 
223
            self.backing_transport = transport.get_transport_from_path('.')
199
224
        self.backing_transport.clone('added-by-filter').ensure_base()
200
225
        self.filter_func = lambda x: 'added-by-filter/' + x
201
226
        super(TestingPathFilteringServer, self).start_server()
213
238
    def start_server(self, backing_server=None):
214
239
        """Setup the Chroot on backing_server."""
215
240
        if backing_server is not None:
216
 
            self.backing_transport = transport.get_transport(
 
241
            self.backing_transport = transport.get_transport_from_url(
217
242
                backing_server.get_url())
218
243
        else:
219
 
            self.backing_transport = transport.get_transport('.')
 
244
            self.backing_transport = transport.get_transport_from_path('.')
220
245
        super(TestingChrootServer, self).start_server()
221
246
 
222
247
    def get_bogus_url(self):
223
248
        raise NotImplementedError
224
249
 
225
250
 
226
 
class SmartTCPServer_for_testing(server.SmartTCPServer):
 
251
class TestThread(cethread.CatchingExceptionThread):
 
252
 
 
253
    def join(self, timeout=5):
 
254
        """Overrides to use a default timeout.
 
255
 
 
256
        The default timeout is set to 5 and should expire only when a thread
 
257
        serving a client connection is hung.
 
258
        """
 
259
        super(TestThread, self).join(timeout)
 
260
        if timeout and self.isAlive():
 
261
            # The timeout expired without joining the thread, the thread is
 
262
            # therefore stucked and that's a failure as far as the test is
 
263
            # concerned. We used to hang here.
 
264
 
 
265
            # FIXME: we need to kill the thread, but as far as the test is
 
266
            # concerned, raising an assertion is too strong. On most of the
 
267
            # platforms, this doesn't occur, so just mentioning the problem is
 
268
            # enough for now -- vila 2010824
 
269
            sys.stderr.write('thread %s hung\n' % (self.name,))
 
270
            #raise AssertionError('thread %s hung' % (self.name,))
 
271
 
 
272
 
 
273
class TestingTCPServerMixin(object):
 
274
    """Mixin to support running socketserver.TCPServer in a thread.
 
275
 
 
276
    Tests are connecting from the main thread, the server has to be run in a
 
277
    separate thread.
 
278
    """
 
279
 
 
280
    def __init__(self):
 
281
        self.started = threading.Event()
 
282
        self.serving = None
 
283
        self.stopped = threading.Event()
 
284
        # We collect the resources used by the clients so we can release them
 
285
        # when shutting down
 
286
        self.clients = []
 
287
        self.ignored_exceptions = None
 
288
 
 
289
    def server_bind(self):
 
290
        self.socket.bind(self.server_address)
 
291
        self.server_address = self.socket.getsockname()
 
292
 
 
293
    def serve(self):
 
294
        self.serving = True
 
295
        # We are listening and ready to accept connections
 
296
        self.started.set()
 
297
        try:
 
298
            while self.serving:
 
299
                # Really a connection but the python framework is generic and
 
300
                # call them requests
 
301
                self.handle_request()
 
302
            # Let's close the listening socket
 
303
            self.server_close()
 
304
        finally:
 
305
            self.stopped.set()
 
306
 
 
307
    def handle_request(self):
 
308
        """Handle one request.
 
309
 
 
310
        The python version swallows some socket exceptions and we don't use
 
311
        timeout, so we override it to better control the server behavior.
 
312
        """
 
313
        request, client_address = self.get_request()
 
314
        if self.verify_request(request, client_address):
 
315
            try:
 
316
                self.process_request(request, client_address)
 
317
            except:
 
318
                self.handle_error(request, client_address)
 
319
        else:
 
320
            self.close_request(request)
 
321
 
 
322
    def get_request(self):
 
323
        return self.socket.accept()
 
324
 
 
325
    def verify_request(self, request, client_address):
 
326
        """Verify the request.
 
327
 
 
328
        Return True if we should proceed with this request, False if we should
 
329
        not even touch a single byte in the socket ! This is useful when we
 
330
        stop the server with a dummy last connection.
 
331
        """
 
332
        return self.serving
 
333
 
 
334
    def handle_error(self, request, client_address):
 
335
        # Stop serving and re-raise the last exception seen
 
336
        self.serving = False
 
337
        # The following can be used for debugging purposes, it will display the
 
338
        # exception and the traceback just when it occurs instead of waiting
 
339
        # for the thread to be joined.
 
340
        # socketserver.BaseServer.handle_error(self, request, client_address)
 
341
 
 
342
        # We call close_request manually, because we are going to raise an
 
343
        # exception. The socketserver implementation calls:
 
344
        #   handle_error(...)
 
345
        #   close_request(...)
 
346
        # But because we raise the exception, close_request will never be
 
347
        # triggered. This helps client not block waiting for a response when
 
348
        # the server gets an exception.
 
349
        self.close_request(request)
 
350
        raise
 
351
 
 
352
    def ignored_exceptions_during_shutdown(self, e):
 
353
        if sys.platform == 'win32':
 
354
            accepted_errnos = [errno.EBADF,
 
355
                               errno.EPIPE,
 
356
                               errno.WSAEBADF,
 
357
                               errno.WSAECONNRESET,
 
358
                               errno.WSAENOTCONN,
 
359
                               errno.WSAESHUTDOWN,
 
360
                               ]
 
361
        else:
 
362
            accepted_errnos = [errno.EBADF,
 
363
                               errno.ECONNRESET,
 
364
                               errno.ENOTCONN,
 
365
                               errno.EPIPE,
 
366
                               ]
 
367
        if isinstance(e, socket.error) and e.errno in accepted_errnos:
 
368
            return True
 
369
        return False
 
370
 
 
371
    # The following methods are called by the main thread
 
372
 
 
373
    def stop_client_connections(self):
 
374
        while self.clients:
 
375
            c = self.clients.pop()
 
376
            self.shutdown_client(c)
 
377
 
 
378
    def shutdown_socket(self, sock):
 
379
        """Properly shutdown a socket.
 
380
 
 
381
        This should be called only when no other thread is trying to use the
 
382
        socket.
 
383
        """
 
384
        try:
 
385
            sock.shutdown(socket.SHUT_RDWR)
 
386
            sock.close()
 
387
        except Exception as e:
 
388
            if self.ignored_exceptions(e):
 
389
                pass
 
390
            else:
 
391
                raise
 
392
 
 
393
    # The following methods are called by the main thread
 
394
 
 
395
    def set_ignored_exceptions(self, thread, ignored_exceptions):
 
396
        self.ignored_exceptions = ignored_exceptions
 
397
        thread.set_ignored_exceptions(self.ignored_exceptions)
 
398
 
 
399
    def _pending_exception(self, thread):
 
400
        """Raise server uncaught exception.
 
401
 
 
402
        Daughter classes can override this if they use daughter threads.
 
403
        """
 
404
        thread.pending_exception()
 
405
 
 
406
 
 
407
class TestingTCPServer(TestingTCPServerMixin, socketserver.TCPServer):
 
408
 
 
409
    def __init__(self, server_address, request_handler_class):
 
410
        TestingTCPServerMixin.__init__(self)
 
411
        socketserver.TCPServer.__init__(self, server_address,
 
412
                                        request_handler_class)
 
413
 
 
414
    def get_request(self):
 
415
        """Get the request and client address from the socket."""
 
416
        sock, addr = TestingTCPServerMixin.get_request(self)
 
417
        self.clients.append((sock, addr))
 
418
        return sock, addr
 
419
 
 
420
    # The following methods are called by the main thread
 
421
 
 
422
    def shutdown_client(self, client):
 
423
        sock, addr = client
 
424
        self.shutdown_socket(sock)
 
425
 
 
426
 
 
427
class TestingThreadingTCPServer(TestingTCPServerMixin,
 
428
                                socketserver.ThreadingTCPServer):
 
429
 
 
430
    def __init__(self, server_address, request_handler_class):
 
431
        TestingTCPServerMixin.__init__(self)
 
432
        socketserver.ThreadingTCPServer.__init__(self, server_address,
 
433
                                                 request_handler_class)
 
434
 
 
435
    def get_request(self):
 
436
        """Get the request and client address from the socket."""
 
437
        sock, addr = TestingTCPServerMixin.get_request(self)
 
438
        # The thread is not created yet, it will be updated in process_request
 
439
        self.clients.append((sock, addr, None))
 
440
        return sock, addr
 
441
 
 
442
    def process_request_thread(self, started, detached, stopped,
 
443
                               request, client_address):
 
444
        started.set()
 
445
        # We will be on our own once the server tells us we're detached
 
446
        detached.wait()
 
447
        socketserver.ThreadingTCPServer.process_request_thread(
 
448
            self, request, client_address)
 
449
        self.close_request(request)
 
450
        stopped.set()
 
451
 
 
452
    def process_request(self, request, client_address):
 
453
        """Start a new thread to process the request."""
 
454
        started = threading.Event()
 
455
        detached = threading.Event()
 
456
        stopped = threading.Event()
 
457
        t = TestThread(
 
458
            sync_event=stopped,
 
459
            name='%s -> %s' % (client_address, self.server_address),
 
460
            target = self.process_request_thread,
 
461
            args = (started, detached, stopped, request, client_address))
 
462
        # Update the client description
 
463
        self.clients.pop()
 
464
        self.clients.append((request, client_address, t))
 
465
        # Propagate the exception handler since we must use the same one as
 
466
        # TestingTCPServer for connections running in their own threads.
 
467
        t.set_ignored_exceptions(self.ignored_exceptions)
 
468
        t.start()
 
469
        started.wait()
 
470
        # If an exception occured during the thread start, it will get raised.
 
471
        t.pending_exception()
 
472
        if debug_threads():
 
473
            sys.stderr.write('Client thread %s started\n' % (t.name,))
 
474
        # Tell the thread, it's now on its own for exception handling.
 
475
        detached.set()
 
476
 
 
477
    # The following methods are called by the main thread
 
478
 
 
479
    def shutdown_client(self, client):
 
480
        sock, addr, connection_thread = client
 
481
        self.shutdown_socket(sock)
 
482
        if connection_thread is not None:
 
483
            # The thread has been created only if the request is processed but
 
484
            # after the connection is inited. This could happen during server
 
485
            # shutdown. If an exception occurred in the thread it will be
 
486
            # re-raised
 
487
            if debug_threads():
 
488
                sys.stderr.write('Client thread %s will be joined\n'
 
489
                                 % (connection_thread.name,))
 
490
            connection_thread.join()
 
491
 
 
492
    def set_ignored_exceptions(self, thread, ignored_exceptions):
 
493
        TestingTCPServerMixin.set_ignored_exceptions(self, thread,
 
494
                                                     ignored_exceptions)
 
495
        for sock, addr, connection_thread in self.clients:
 
496
            if connection_thread is not None:
 
497
                connection_thread.set_ignored_exceptions(
 
498
                    self.ignored_exceptions)
 
499
 
 
500
    def _pending_exception(self, thread):
 
501
        for sock, addr, connection_thread in self.clients:
 
502
            if connection_thread is not None:
 
503
                connection_thread.pending_exception()
 
504
        TestingTCPServerMixin._pending_exception(self, thread)
 
505
 
 
506
 
 
507
class TestingTCPServerInAThread(transport.Server):
 
508
    """A server in a thread that re-raise thread exceptions."""
 
509
 
 
510
    def __init__(self, server_address, server_class, request_handler_class):
 
511
        self.server_class = server_class
 
512
        self.request_handler_class = request_handler_class
 
513
        self.host, self.port = server_address
 
514
        self.server = None
 
515
        self._server_thread = None
 
516
 
 
517
    def __repr__(self):
 
518
        return "%s(%s:%s)" % (self.__class__.__name__, self.host, self.port)
 
519
 
 
520
    def create_server(self):
 
521
        return self.server_class((self.host, self.port),
 
522
                                 self.request_handler_class)
 
523
 
 
524
    def start_server(self):
 
525
        self.server = self.create_server()
 
526
        self._server_thread = TestThread(
 
527
            sync_event=self.server.started,
 
528
            target=self.run_server)
 
529
        self._server_thread.start()
 
530
        # Wait for the server thread to start (i.e. release the lock)
 
531
        self.server.started.wait()
 
532
        # Get the real address, especially the port
 
533
        self.host, self.port = self.server.server_address
 
534
        self._server_thread.name = self.server.server_address
 
535
        if debug_threads():
 
536
            sys.stderr.write('Server thread %s started\n'
 
537
                             % (self._server_thread.name,))
 
538
        # If an exception occured during the server start, it will get raised,
 
539
        # otherwise, the server is blocked on its accept() call.
 
540
        self._server_thread.pending_exception()
 
541
        # From now on, we'll use a different event to ensure the server can set
 
542
        # its exception
 
543
        self._server_thread.set_sync_event(self.server.stopped)
 
544
 
 
545
    def run_server(self):
 
546
        self.server.serve()
 
547
 
 
548
    def stop_server(self):
 
549
        if self.server is None:
 
550
            return
 
551
        try:
 
552
            # The server has been started successfully, shut it down now.  As
 
553
            # soon as we stop serving, no more connection are accepted except
 
554
            # one to get out of the blocking listen.
 
555
            self.set_ignored_exceptions(
 
556
                self.server.ignored_exceptions_during_shutdown)
 
557
            self.server.serving = False
 
558
            if debug_threads():
 
559
                sys.stderr.write('Server thread %s will be joined\n'
 
560
                                 % (self._server_thread.name,))
 
561
            # The server is listening for a last connection, let's give it:
 
562
            last_conn = None
 
563
            try:
 
564
                last_conn = osutils.connect_socket((self.host, self.port))
 
565
            except socket.error as e:
 
566
                # But ignore connection errors as the point is to unblock the
 
567
                # server thread, it may happen that it's not blocked or even
 
568
                # not started.
 
569
                pass
 
570
            # We start shutting down the clients while the server itself is
 
571
            # shutting down.
 
572
            self.server.stop_client_connections()
 
573
            # Now we wait for the thread running self.server.serve() to finish
 
574
            self.server.stopped.wait()
 
575
            if last_conn is not None:
 
576
                # Close the last connection without trying to use it. The
 
577
                # server will not process a single byte on that socket to avoid
 
578
                # complications (SSL starts with a handshake for example).
 
579
                last_conn.close()
 
580
            # Check for any exception that could have occurred in the server
 
581
            # thread
 
582
            try:
 
583
                self._server_thread.join()
 
584
            except Exception as e:
 
585
                if self.server.ignored_exceptions(e):
 
586
                    pass
 
587
                else:
 
588
                    raise
 
589
        finally:
 
590
            # Make sure we can be called twice safely, note that this means
 
591
            # that we will raise a single exception even if several occurred in
 
592
            # the various threads involved.
 
593
            self.server = None
 
594
 
 
595
    def set_ignored_exceptions(self, ignored_exceptions):
 
596
        """Install an exception handler for the server."""
 
597
        self.server.set_ignored_exceptions(self._server_thread,
 
598
                                           ignored_exceptions)
 
599
 
 
600
    def pending_exception(self):
 
601
        """Raise uncaught exception in the server."""
 
602
        self.server._pending_exception(self._server_thread)
 
603
 
 
604
 
 
605
class TestingSmartConnectionHandler(socketserver.BaseRequestHandler,
 
606
                                    medium.SmartServerSocketStreamMedium):
 
607
 
 
608
    def __init__(self, request, client_address, server):
 
609
        medium.SmartServerSocketStreamMedium.__init__(
 
610
            self, request, server.backing_transport,
 
611
            server.root_client_path,
 
612
            timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
 
613
        request.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
 
614
        socketserver.BaseRequestHandler.__init__(self, request, client_address,
 
615
                                                 server)
 
616
 
 
617
    def handle(self):
 
618
        try:
 
619
            while not self.finished:
 
620
                server_protocol = self._build_protocol()
 
621
                self._serve_one_request(server_protocol)
 
622
        except errors.ConnectionTimeout:
 
623
            # idle connections aren't considered a failure of the server
 
624
            return
 
625
 
 
626
 
 
627
_DEFAULT_TESTING_CLIENT_TIMEOUT = 60.0
 
628
 
 
629
class TestingSmartServer(TestingThreadingTCPServer, server.SmartTCPServer):
 
630
 
 
631
    def __init__(self, server_address, request_handler_class,
 
632
                 backing_transport, root_client_path):
 
633
        TestingThreadingTCPServer.__init__(self, server_address,
 
634
                                           request_handler_class)
 
635
        server.SmartTCPServer.__init__(self, backing_transport,
 
636
            root_client_path, client_timeout=_DEFAULT_TESTING_CLIENT_TIMEOUT)
 
637
 
 
638
    def serve(self):
 
639
        self.run_server_started_hooks()
 
640
        try:
 
641
            TestingThreadingTCPServer.serve(self)
 
642
        finally:
 
643
            self.run_server_stopped_hooks()
 
644
 
 
645
    def get_url(self):
 
646
        """Return the url of the server"""
 
647
        return "bzr://%s:%d/" % self.server_address
 
648
 
 
649
 
 
650
class SmartTCPServer_for_testing(TestingTCPServerInAThread):
227
651
    """Server suitable for use by transport tests.
228
652
 
229
653
    This server is backed by the process's cwd.
230
654
    """
231
 
 
232
655
    def __init__(self, thread_name_suffix=''):
233
 
        super(SmartTCPServer_for_testing, self).__init__(None)
234
656
        self.client_path_extra = None
235
657
        self.thread_name_suffix = thread_name_suffix
236
 
 
237
 
    def get_backing_transport(self, backing_transport_server):
238
 
        """Get a backing transport from a server we are decorating."""
239
 
        return transport.get_transport(backing_transport_server.get_url())
 
658
        self.host = '127.0.0.1'
 
659
        self.port = 0
 
660
        super(SmartTCPServer_for_testing, self).__init__(
 
661
                (self.host, self.port),
 
662
                TestingSmartServer,
 
663
                TestingSmartConnectionHandler)
 
664
 
 
665
    def create_server(self):
 
666
        return self.server_class((self.host, self.port),
 
667
                                 self.request_handler_class,
 
668
                                 self.backing_transport,
 
669
                                 self.root_client_path)
 
670
 
240
671
 
241
672
    def start_server(self, backing_transport_server=None,
242
 
              client_path_extra='/extra/'):
 
673
                     client_path_extra='/extra/'):
243
674
        """Set up server for testing.
244
675
 
245
676
        :param backing_transport_server: backing server to use.  If not
254
685
        """
255
686
        if not client_path_extra.startswith('/'):
256
687
            raise ValueError(client_path_extra)
257
 
        from bzrlib.transport.chroot import ChrootServer
 
688
        self.root_client_path = self.client_path_extra = client_path_extra
 
689
        from breezy.transport.chroot import ChrootServer
258
690
        if backing_transport_server is None:
259
691
            backing_transport_server = LocalURLServer()
260
692
        self.chroot_server = ChrootServer(
261
693
            self.get_backing_transport(backing_transport_server))
262
694
        self.chroot_server.start_server()
263
 
        self.backing_transport = transport.get_transport(
 
695
        self.backing_transport = transport.get_transport_from_url(
264
696
            self.chroot_server.get_url())
265
 
        self.root_client_path = self.client_path_extra = client_path_extra
266
 
        self.start_background_thread(self.thread_name_suffix)
 
697
        super(SmartTCPServer_for_testing, self).start_server()
267
698
 
268
699
    def stop_server(self):
269
 
        self.stop_background_thread()
270
 
        self.chroot_server.stop_server()
 
700
        try:
 
701
            super(SmartTCPServer_for_testing, self).stop_server()
 
702
        finally:
 
703
            self.chroot_server.stop_server()
 
704
 
 
705
    def get_backing_transport(self, backing_transport_server):
 
706
        """Get a backing transport from a server we are decorating."""
 
707
        return transport.get_transport_from_url(
 
708
            backing_transport_server.get_url())
271
709
 
272
710
    def get_url(self):
273
 
        url = super(SmartTCPServer_for_testing, self).get_url()
 
711
        url = self.server.get_url()
274
712
        return url[:-1] + self.client_path_extra
275
713
 
276
714
    def get_bogus_url(self):
284
722
    def get_backing_transport(self, backing_transport_server):
285
723
        """Get a backing transport from a server we are decorating."""
286
724
        url = 'readonly+' + backing_transport_server.get_url()
287
 
        return transport.get_transport(url)
 
725
        return transport.get_transport_from_url(url)
288
726
 
289
727
 
290
728
class SmartTCPServer_for_testing_v2_only(SmartTCPServer_for_testing):
305
743
    def get_backing_transport(self, backing_transport_server):
306
744
        """Get a backing transport from a server we are decorating."""
307
745
        url = 'readonly+' + backing_transport_server.get_url()
308
 
        return transport.get_transport(url)
309
 
 
310
 
 
311
 
 
312
 
 
 
746
        return transport.get_transport_from_url(url)