MCPcopy
hub / github.com/cherrypy/cherrypy / testEndRequestOnDrop

Method testEndRequestOnDrop

cherrypy/test/test_tools.py:311–342  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

309 self.assertBody('Welcome!')
310
311 def testEndRequestOnDrop(self):
312 old_timeout = None
313 try:
314 httpserver = cherrypy.server.httpserver
315 old_timeout = httpserver.timeout
316 except (AttributeError, IndexError):
317 return self.skip()
318
319 try:
320 httpserver.timeout = timeout
321
322 # Test that on_end_request is called even if the client drops.
323 self.persistent = True
324 try:
325 conn = self.HTTP_CONN
326 conn.putrequest('GET', '/demo/stream?id=9', skip_host=True)
327 conn.putheader('Host', self.HOST)
328 conn.endheaders()
329 # Skip the rest of the request and close the conn. This will
330 # cause the server's active socket to error, which *should*
331 # result in the request being aborted, and request.close being
332 # called all the way up the stack (including WSGI middleware),
333 # eventually calling our on_end_request hook.
334 finally:
335 self.persistent = False
336 time.sleep(timeout * 2)
337 # Test that the on_end_request hook was called.
338 self.getPage('/demo/ended/9')
339 self.assertBody('True')
340 finally:
341 if old_timeout is not None:
342 httpserver.timeout = old_timeout
343
344 def testGuaranteedHooks(self):
345 # The 'critical' on_start_resource hook is 'failsafe' (guaranteed

Callers

nothing calls this directly

Calls 2

skipMethod · 0.80
getPageMethod · 0.80

Tested by

no test coverage detected