~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/server.py

  • Committer: Vincent Ladeuil
  • Date: 2009-09-19 16:14:10 UTC
  • mto: (4707.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4708.
  • Revision ID: v.ladeuil+lp@free.fr-20090919161410-lmlunl2q9kbzd3x0
Fix OSX and FreeBSD failures.

* bzrlib/tests/__init__.py:
(TestCaseWithMemoryTransport._make_test_root): Fixing the problem
at the root, if we usr the real path there, we catch 99% of the
consequences.

* bzrlib/tests/test_osutils.py:
(TestCanonicalRelPath.test_canonical_relpath_simple,
TestCanonicalRelPath.test_canonical_relpath_missing_tail): No need
to use realpath here anymore.

* bzrlib/tests/script.py:
(ScriptRunner.do_rm): OSX and BSD raises a different exception,
and windows too even if that will require real testing (but
osutils._delete_file_or_dir use the same trick for unlink so it's
a pretty safe bet).

* bzrlib/tests/blackbox/test_outside_wt.py:
(TestOutsideWT.test_cwd_log,
TestOutsideWT.test_diff_outside_tree): Watch for OSX trick.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
138
138
                        if e.args[0] != errno.EBADF:
139
139
                            trace.warning("listening socket error: %s", e)
140
140
                    else:
141
 
                        if self._should_terminate:
142
 
                            break
143
141
                        self.serve_conn(conn, thread_name_suffix)
144
142
            except KeyboardInterrupt:
145
143
                # dont log when CTRL-C'd.
146
144
                raise
147
145
            except Exception, e:
148
 
                trace.report_exception(sys.exc_info(), sys.stderr)
 
146
                trace.error("Unhandled smart server error.")
 
147
                trace.log_exception_quietly()
149
148
                raise
150
149
        finally:
151
150
            self._stopped.set()
238
237
SmartTCPServer.hooks = SmartServerHooks()
239
238
 
240
239
 
 
240
class SmartTCPServer_for_testing(SmartTCPServer):
 
241
    """Server suitable for use by transport tests.
 
242
 
 
243
    This server is backed by the process's cwd.
 
244
    """
 
245
 
 
246
    def __init__(self, thread_name_suffix=''):
 
247
        SmartTCPServer.__init__(self, None)
 
248
        self.client_path_extra = None
 
249
        self.thread_name_suffix = thread_name_suffix
 
250
 
 
251
    def get_backing_transport(self, backing_transport_server):
 
252
        """Get a backing transport from a server we are decorating."""
 
253
        return transport.get_transport(backing_transport_server.get_url())
 
254
 
 
255
    def setUp(self, backing_transport_server=None,
 
256
              client_path_extra='/extra/'):
 
257
        """Set up server for testing.
 
258
 
 
259
        :param backing_transport_server: backing server to use.  If not
 
260
            specified, a LocalURLServer at the current working directory will
 
261
            be used.
 
262
        :param client_path_extra: a path segment starting with '/' to append to
 
263
            the root URL for this server.  For instance, a value of '/foo/bar/'
 
264
            will mean the root of the backing transport will be published at a
 
265
            URL like `bzr://127.0.0.1:nnnn/foo/bar/`, rather than
 
266
            `bzr://127.0.0.1:nnnn/`.  Default value is `extra`, so that tests
 
267
            by default will fail unless they do the necessary path translation.
 
268
        """
 
269
        if not client_path_extra.startswith('/'):
 
270
            raise ValueError(client_path_extra)
 
271
        from bzrlib.transport.chroot import ChrootServer
 
272
        if backing_transport_server is None:
 
273
            from bzrlib.transport.local import LocalURLServer
 
274
            backing_transport_server = LocalURLServer()
 
275
        self.chroot_server = ChrootServer(
 
276
            self.get_backing_transport(backing_transport_server))
 
277
        self.chroot_server.setUp()
 
278
        self.backing_transport = transport.get_transport(
 
279
            self.chroot_server.get_url())
 
280
        self.root_client_path = self.client_path_extra = client_path_extra
 
281
        self.start_background_thread(self.thread_name_suffix)
 
282
 
 
283
    def tearDown(self):
 
284
        self.stop_background_thread()
 
285
        self.chroot_server.tearDown()
 
286
 
 
287
    def get_url(self):
 
288
        url = super(SmartTCPServer_for_testing, self).get_url()
 
289
        return url[:-1] + self.client_path_extra
 
290
 
 
291
    def get_bogus_url(self):
 
292
        """Return a URL which will fail to connect"""
 
293
        return 'bzr://127.0.0.1:1/'
 
294
 
 
295
 
 
296
class ReadonlySmartTCPServer_for_testing(SmartTCPServer_for_testing):
 
297
    """Get a readonly server for testing."""
 
298
 
 
299
    def get_backing_transport(self, backing_transport_server):
 
300
        """Get a backing transport from a server we are decorating."""
 
301
        url = 'readonly+' + backing_transport_server.get_url()
 
302
        return transport.get_transport(url)
 
303
 
 
304
 
 
305
class SmartTCPServer_for_testing_v2_only(SmartTCPServer_for_testing):
 
306
    """A variation of SmartTCPServer_for_testing that limits the client to
 
307
    using RPCs in protocol v2 (i.e. bzr <= 1.5).
 
308
    """
 
309
 
 
310
    def get_url(self):
 
311
        url = super(SmartTCPServer_for_testing_v2_only, self).get_url()
 
312
        url = 'bzr-v2://' + url[len('bzr://'):]
 
313
        return url
 
314
 
 
315
 
 
316
class ReadonlySmartTCPServer_for_testing_v2_only(SmartTCPServer_for_testing_v2_only):
 
317
    """Get a readonly server for testing."""
 
318
 
 
319
    def get_backing_transport(self, backing_transport_server):
 
320
        """Get a backing transport from a server we are decorating."""
 
321
        url = 'readonly+' + backing_transport_server.get_url()
 
322
        return transport.get_transport(url)
 
323
 
 
324
 
241
325
def _local_path_for_transport(transport):
242
326
    """Return a local path for transport, if reasonably possible.
243
327
    
303
387
        """Chroot transport, and decorate with userdir expander."""
304
388
        self.base_path = self.get_base_path(transport)
305
389
        chroot_server = chroot.ChrootServer(transport)
306
 
        chroot_server.start_server()
307
 
        self.cleanups.append(chroot_server.stop_server)
 
390
        chroot_server.setUp()
 
391
        self.cleanups.append(chroot_server.tearDown)
308
392
        transport = get_transport(chroot_server.get_url())
309
393
        if self.base_path is not None:
310
394
            # Decorate the server's backing transport with a filter that can
311
395
            # expand homedirs.
312
396
            expand_userdirs = self._make_expand_userdirs_filter(transport)
313
 
            expand_userdirs.start_server()
314
 
            self.cleanups.append(expand_userdirs.stop_server)
 
397
            expand_userdirs.setUp()
 
398
            self.cleanups.append(expand_userdirs.tearDown)
315
399
            transport = get_transport(expand_userdirs.get_url())
316
400
        self.transport = transport
317
401