/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/http_server.py

  • Committer: Vincent Ladeuil
  • Date: 2010-05-31 20:23:51 UTC
  • mto: (5247.6.1 http-leaks)
  • mto: This revision was merged to the branch mainline in revision 5396.
  • Revision ID: v.ladeuil+lp@free.fr-20100531202351-nc8woo97rbzoxubq
Some notes for defining TestingServerInAThread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
        return path
316
316
 
317
317
 
 
318
# FIXME: This should be called TestingServerInAThread
318
319
class TestingHTTPServerMixin:
319
320
 
320
321
    def __init__(self, test_case_server):
415
416
            # concerned. We used to hang here.
416
417
            raise AssertionError('thread %s hung' % (thread.name,))
417
418
 
418
 
    def shutdown(self):
 
419
    def shutdown_server(self):
419
420
        """Stops the serve() loop.
420
421
 
421
422
        Blocks until the loop has finished. This must be called while serve()
470
471
            # The request process has been completed, the thread is about to
471
472
            # die, let's shutdown the socket if we can.
472
473
            sock.shutdown(socket.SHUT_RDWR)
 
474
            sock.close()
473
475
        except (socket.error, select.error), e:
474
476
            if e[0] in (errno.EBADF, errno.ENOTCONN):
475
477
                # Right, the socket is already down
479
481
                raise
480
482
 
481
483
 
 
484
# FIXME: TestingHTTPServerMixin shouldn't be first -- vila 20100531
482
485
class TestingHTTPServer(TestingHTTPServerMixin, SocketServer.TCPServer):
483
486
 
484
487
    def __init__(self, server_address, request_handler_class,
495
498
        TestingHTTPServerMixin.server_bind(self)
496
499
 
497
500
 
 
501
# FIXME: TestingHTTPServerMixin shouldn't be first -- vila 20100531
498
502
class TestingThreadingHTTPServer(TestingHTTPServerMixin,
499
503
                                 SocketServer.ThreadingTCPServer,
500
504
                                 ):
550
554
        TestingHTTPServerMixin.shutdown_client(self, client)
551
555
        if len(client) == 3:
552
556
            # The thread has been created only if the request is processed but
553
 
            # after the connection is inited. This could happne when the server
554
 
            # is shut down.
 
557
            # after the connection is inited. This could happen during server
 
558
            # shutdown.
555
559
            sock, addr, thread = client
556
560
            if 'threads' in tests.selftest_debug_flags:
557
561
                print 'Try    joining: %s' % (thread.name,)
693
697
        """See bzrlib.transport.Server.tearDown."""
694
698
        if self._httpd is not None:
695
699
            # The server has been started successfully, shut it down now
696
 
            self._httpd.shutdown()
 
700
            self._httpd.shutdown_server()
697
701
            if 'threads' in tests.selftest_debug_flags:
698
702
                print 'Try    joining: %s' % (self._http_thread.name,)
699
703
            self._httpd.join_thread(self._http_thread)