
    gN                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ  G d d      Z G d d	ee	      Z G d
 dee	      Zy)    N)	validator)
RuleRouter)AsyncHTTPTestCasegen_test)WSGIContainerc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)WSGIAppMixinc                     t               N)NotImplementedErrorselfs    K/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/wsgi_test.pyget_executorzWSGIAppMixin.get_executor   s    !##    c                     | j                         t        j                  dd      | _        fd}t	        d || j
                        fd || j                        fd || j                        fg      S )N   g333333?)timeoutc                 0    t        t        |             S )N)executor)r   r   )appr   s    r   make_containerz,WSGIAppMixin.get_app.<locals>.make_container   s     3(CCr   /simple/barrier/streaming_barrier)r   	threadingBarrierbarrierr   simple_wsgi_appbarrier_wsgi_appstreaming_barrier_wsgi_app)r   r   r   s     @r   get_appzWSGIAppMixin.get_app   sz    $$& !((C8	D N4+?+?@A^D,A,ABC%~d6U6U'VW
 	
r   c                      d}dg} |||       y )Nz200 OK)zContent-Typez
text/plain )r   start_responsestatusresponse_headerss       r   respond_plainzWSGIAppMixin.respond_plain"   s    :;v/0r   c                 *    | j                  |       dgS )N   Hello world!)r(   )r   environr%   s      r   r   zWSGIAppMixin.simple_wsgi_app'   s    >*  r   c                     | j                  |       	 | j                  j                         }d|z  gS # t        j                  $ r dgcY S w xY w)Ns   ok %d   broken barrierr(   r   waitr   BrokenBarrierErrorr   r+   r%   ns       r   r    zWSGIAppMixin.barrier_wsgi_app+   sU    >*	"!!#A qL>! ++ 	'%&&	's   3 AAc              #      K   | j                  |       d 	 | j                  j                         }d|z   y # t        j                  $ r d Y y w xY ww)Ns   ok s   %dr-   r.   r1   s       r   r!   z'WSGIAppMixin.streaming_barrier_wsgi_app4   sW     >*	!!#A !)O ++ 	$##	$s%   A; AAAAAN)	__name__
__module____qualname__r   r"   r(   r   r    r!   r$   r   r   r	   r	      s     $
"1
!"r   r	   c                   8    e Zd Zd Zd Zed        Zed        Zy)WSGIContainerDummyExecutorTestc                      y r   r$   r   s    r   r   z+WSGIContainerDummyExecutorTest.get_executor@   s    r   c                 ^    | j                  d      }| j                  |j                  d       y Nr   r*   fetchassertEqualbodyr   responses     r   test_simplez*WSGIContainerDummyExecutorTest.test_simpleC   $    ::i(8r   c                 f  K   | j                   j                          t        j                  | j                  j                  | j                  d            | j                  j                  | j                  d                   d {   }|D ]  }| j                  |j                  d         y 7 (w)Nr   r-   	r   resetasynciogatherhttp_clientr=   get_urlr>   r?   r   respsresps      r   test_concurrent_barrierz6WSGIContainerDummyExecutorTest.test_concurrent_barrierG   s     nn""4<<
#;<""4<<
#;<
 
 DTYY(9: 	
   BB1B/)B1c                 f  K   | j                   j                          t        j                  | j                  j                  | j                  d            | j                  j                  | j                  d                   d {   }|D ]  }| j                  |j                  d         y 7 (w)Nr   s   ok broken barrierrE   rK   s      r   !test_concurrent_streaming_barrierz@WSGIContainerDummyExecutorTest.test_concurrent_streaming_barrierQ   s     nn""4<<0D#EF""4<<0D#EF
 
 DTYY(<= 	
rO   Nr4   r5   r6   r   rB   r   rN   rQ   r$   r   r   r8   r8   ?   s4    9 ; ; > >r   r8   c                   8    e Zd Zd Zd Zed        Zed        Zy)WSGIContainerThreadPoolTestc                 >    t         j                  j                         S r   )
concurrentfuturesThreadPoolExecutorr   s    r   r   z(WSGIContainerThreadPoolTest.get_executor]   s    !!4466r   c                 ^    | j                  d      }| j                  |j                  d       y r;   r<   r@   s     r   rB   z'WSGIContainerThreadPoolTest.test_simple`   rC   r   c           	        K   | j                   j                          t        j                  | j                  j                  | j                  d            | j                  j                  | j                  d                   d {   }| j                  ddgt        |D cg c]  }|j                   c}             y 7 :c c}w w)Nr      ok 0   ok 1
r   rF   rG   rH   rI   r=   rJ   r>   sortedr?   rK   s      r   rN   z3WSGIContainerThreadPoolTest.test_concurrent_barrierd   s     nn""4<<
#;<""4<<
#;<
 
 	'7+V54Q54TYY54Q-RS	
 5R$   BCCC"C5CCc           	        K   | j                   j                          t        j                  | j                  j                  | j                  d            | j                  j                  | j                  d                   d {   }| j                  ddgt        |D cg c]  }|j                   c}             y 7 :c c}w w)Nr   r[   r\   r]   rK   s      r   rQ   z=WSGIContainerThreadPoolTest.test_concurrent_streaming_barrierm   s     nn""4<<0D#EF""4<<0D#EF
 
 	'7+V54Q54TYY54Q-RS	
 5Rr_   NrR   r$   r   r   rT   rT   \   s8    79 T T T Tr   rT   )rG   concurrent.futuresrV   r   wsgiref.validater   tornado.routingr   tornado.testingr   r   tornado.wsgir   r	   r8   rT   r$   r   r   <module>rf      sE       & & 7 &0 0f>\3D >:T,0A Tr   