~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HttpServer.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-03 01:53:30 UTC
  • mfrom: (2955.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071103015330-pt1tec7wyxwwcey8
Fix #158972 don't use timeout for HttpServer

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        connection early to avoid polluting the test results.
65
65
        """
66
66
        try:
67
 
            self._handle_one_request()
 
67
            SimpleHTTPRequestHandler.handle_one_request(self)
68
68
        except socket.error, e:
69
69
            if (len(e.args) > 0
70
70
                and e.args[0] in (errno.EPIPE, errno.ECONNRESET,
74
74
            else:
75
75
                raise
76
76
 
77
 
    def _handle_one_request(self):
78
 
        """
79
 
        Request handling as defined in the base class.
80
 
 
81
 
        You normally don't need to override this method; see the class
82
 
        __doc__ string for information on how to handle specific HTTP
83
 
        commands such as GET and POST.
84
 
 
85
 
        On some platforms, notably OS X, a lot of EAGAIN (resource temporary
86
 
        unavailable) occur. We retry silently at most 10 times.
87
 
        """
88
 
        for i in xrange(1,11): # Don't try more than 10 times
89
 
            try:
90
 
                self.raw_requestline = self.rfile.readline()
91
 
            except socket.error, e:
92
 
                if e.args[0] in (errno.EAGAIN, errno.EWOULDBLOCK):
93
 
                    # omitted for now because some tests look at the log of
94
 
                    # the server and expect to see no errors.  see recent
95
 
                    # email thread. -- mbp 20051021. 
96
 
                    ## self.log_message('EAGAIN (%d) while reading from raw_requestline' % i)
97
 
                    time.sleep(0.01)
98
 
                    continue
99
 
                raise
100
 
            else:
101
 
                break
102
 
        if not self.raw_requestline:
103
 
            self.close_connection = 1
104
 
            return
105
 
        if not self.parse_request(): # An error code has been sent, just exit
106
 
            return
107
 
        mname = 'do_' + self.command
108
 
        if getattr(self, mname, None) is None:
109
 
            self.send_error(501, "Unsupported method (%r)" % self.command)
110
 
            return
111
 
        method = getattr(self, mname)
112
 
        method()
113
 
 
114
77
    _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
115
78
    _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
116
79
 
311
274
        # the tests cases.
312
275
        self.test_case_server = test_case_server
313
276
 
 
277
    def server_close(self):
 
278
        """Called to clean-up the server.
 
279
 
 
280
        Since the server may be in a blocking read, we shutdown the socket
 
281
        before closing it.
 
282
        """
 
283
        self.socket.shutdown(socket.SHUT_RDWR)
 
284
        BaseHTTPServer.HTTPServer.server_close(self)
 
285
 
314
286
 
315
287
class HttpServer(Server):
316
288
    """A test server for http transports.
346
318
        self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
347
319
                                               self.host,
348
320
                                               self.port)
349
 
        httpd.socket.settimeout(0.1)
350
321
        self._http_starting.release()
351
322
 
352
323
        while self._http_running: