~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/http_server.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
318
318
        self.test_case_server = test_case_server
319
319
        self._home_dir = test_case_server._home_dir
320
320
 
321
 
    def tearDown(self):
 
321
    def stop_server(self):
322
322
         """Called to clean-up the server.
323
323
 
324
324
         Since the server may be (surely is, even) in a blocking listen, we
347
347
             # 'Socket is not connected' can also occur on OSX, with a
348
348
             # "regular" ENOTCONN (when something went wrong during test case
349
349
             # setup leading to self.setUp() *not* being called but
350
 
             # self.tearDown() still being called -- vila20081106
 
350
             # self.stop_server() still being called -- vila20081106
351
351
             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
352
352
                 raise
353
353
         # Let the server properly close the socket
462
462
                raise httplib.UnknownProtocol(proto_vers)
463
463
            else:
464
464
                self._httpd = self.create_httpd(serv_cls, rhandler)
465
 
            host, self.port = self._httpd.socket.getsockname()
 
465
            self.host, self.port = self._httpd.socket.getsockname()
466
466
        return self._httpd
467
467
 
468
468
    def _http_start(self):
494
494
            except socket.timeout:
495
495
                pass
496
496
            except (socket.error, select.error), e:
497
 
               if e[0] == errno.EBADF:
498
 
                   # Starting with python-2.6, handle_request may raise socket
499
 
                   # or select exceptions when the server is shut down (as we
500
 
                   # do).
501
 
                   pass
502
 
               else:
503
 
                   raise
 
497
                if (e[0] == errno.EBADF
 
498
                    or (sys.platform == 'win32' and e[0] == 10038)):
 
499
                    # Starting with python-2.6, handle_request may raise socket
 
500
                    # or select exceptions when the server is shut down (as we
 
501
                    # do).
 
502
                    # 10038 = WSAENOTSOCK
 
503
                    # http://msdn.microsoft.com/en-us/library/ms740668%28VS.85%29.aspx
 
504
                    pass
 
505
                else:
 
506
                    raise
504
507
 
505
508
    def _get_remote_url(self, path):
506
509
        path_parts = path.split(os.path.sep)
518
521
        """Capture Server log output."""
519
522
        self.logs.append(format % args)
520
523
 
521
 
    def setUp(self, backing_transport_server=None):
522
 
        """See bzrlib.transport.Server.setUp.
 
524
    def start_server(self, backing_transport_server=None):
 
525
        """See bzrlib.transport.Server.start_server.
523
526
 
524
527
        :param backing_transport_server: The transport that requests over this
525
528
            protocol should be forwarded to. Note that this is currently not
554
557
        self._http_starting.release()
555
558
        self.logs = []
556
559
 
557
 
    def tearDown(self):
558
 
        """See bzrlib.transport.Server.tearDown."""
559
 
        self._httpd.tearDown()
 
560
    def stop_server(self):
 
561
        self._httpd.stop_server()
560
562
        self._http_running = False
561
563
        # We don't need to 'self._http_thread.join()' here since the thread is
562
564
        # a daemonic one and will be garbage collected anyway. Joining just