MCPcopy
hub / github.com/cherrypy/cherrypy / test_queue_full

Method test_queue_full

cherrypy/test/test_conn.py:779–841  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

777 setup_server = staticmethod(setup_upload_server)
778
779 def test_queue_full(self):
780 conns = []
781 overflow_conn = None
782
783 try:
784 # Make 15 initial requests and leave them open, which should use
785 # all of wsgiserver's WorkerThreads and fill its Queue.
786 for i in range(15):
787 conn = self.HTTP_CONN(self.HOST, self.PORT)
788 conn.putrequest('POST', '/upload', skip_host=True)
789 conn.putheader('Host', self.HOST)
790 conn.putheader('Content-Type', 'text/plain')
791 conn.putheader('Content-Length', '4')
792 conn.endheaders()
793 conns.append(conn)
794
795 # Now try a 16th conn, which should be closed by the
796 # server immediately.
797 overflow_conn = self.HTTP_CONN(self.HOST, self.PORT)
798 # Manually connect since httplib won't let us set a timeout
799 for res in socket.getaddrinfo(self.HOST, self.PORT, 0,
800 socket.SOCK_STREAM):
801 af, socktype, proto, canonname, sa = res
802 overflow_conn.sock = socket.socket(af, socktype, proto)
803 overflow_conn.sock.settimeout(5)
804 overflow_conn.sock.connect(sa)
805 break
806
807 overflow_conn.putrequest('GET', '/', skip_host=True)
808 overflow_conn.putheader('Host', self.HOST)
809 overflow_conn.endheaders()
810 response = overflow_conn.response_class(
811 overflow_conn.sock,
812 method='GET',
813 )
814 try:
815 response.begin()
816 except socket.error as exc:
817 if exc.args[0] in socket_reset_errors:
818 pass # Expected.
819 else:
820 tmpl = (
821 'Overflow conn did not get RST. '
822 'Got {exc.args!r} instead'
823 )
824 raise AssertionError(tmpl.format(**locals()))
825 except BadStatusLine:
826 # This is a special case in OS X. Linux and Windows will
827 # RST correctly.
828 assert sys.platform == 'darwin'
829 else:
830 raise AssertionError('Overflow conn did not get RST ')
831 finally:
832 for conn in conns:
833 conn.send(b'done')
834 response = conn.response_class(conn.sock, method='POST')
835 response.begin()
836 self.body = response.read()

Callers

nothing calls this directly

Calls 4

formatMethod · 0.80
connectMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected