o
    ~îjN  ã                   @   s‚   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„ dƒZG dd	„ d	ee	ƒZG d
d„ dee	ƒZdS )é    N)Ú	validator)Ú
RuleRouter)ÚAsyncHTTPTestCaseÚgen_test)ÚWSGIContainerc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚWSGIAppMixinc                 C   s   t ƒ ‚©N)ÚNotImplementedError©Úself© r   ú`/raid/bulk_storage/M2HATS/real-image-venv/lib/python3.10/site-packages/tornado/test/wsgi_test.pyÚget_executor   s   zWSGIAppMixin.get_executorc                    sP   |   ¡ ‰ tjddd�| _‡ fdd„}td|| jƒfd|| jƒfd|| jƒfgƒS )	Né   g333333Ó?)Útimeoutc                    s   t t| ƒˆ d�S )N©Úexecutor)r   r   )Úappr   r   r   Úmake_container   s   z,WSGIAppMixin.get_app.<locals>.make_containerú/simpleú/barrierú/streaming_barrier)r   Ú	threadingÚBarrierÚbarrierr   Úsimple_wsgi_appÚbarrier_wsgi_appÚstreaming_barrier_wsgi_app)r   r   r   r   r   Úget_app   s   ýÿzWSGIAppMixin.get_appc                 C   s   d}dg}|||ƒ d S )Nz200 OK)zContent-Typez
text/plainr   )r   Ústart_responseÚstatusÚresponse_headersr   r   r   Úrespond_plain"   s   zWSGIAppMixin.respond_plainc                 C   s   |   |¡ dgS )Nó   Hello world!)r"   )r   Úenvironr   r   r   r   r   '   s   
zWSGIAppMixin.simple_wsgi_appc                 C   s>   |   |¡ z| j ¡ }W n tjy   dg Y S w d| gS )Nó   broken barriers   ok %d©r"   r   Úwaitr   ÚBrokenBarrierError©r   r$   r   Únr   r   r   r   +   s   

ÿ
zWSGIAppMixin.barrier_wsgi_appc                 c   sL   � |   |¡ dV  z| j ¡ }W n tjy   dV  Y d S w d| V  d S )Ns   ok r%   s   %dr&   r)   r   r   r   r   4   s   €
ÿz'WSGIAppMixin.streaming_barrier_wsgi_appN)	Ú__name__Ú
__module__Ú__qualname__r   r   r"   r   r   r   r   r   r   r   r      s    	r   c                   @   ó4   e Zd Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZd	S )
ÚWSGIContainerDummyExecutorTestc                 C   s   d S r   r   r
   r   r   r   r   @   s   z+WSGIContainerDummyExecutorTest.get_executorc                 C   ó   |   d¡}|  |jd¡ d S ©Nr   r#   ©ÚfetchÚassertEqualÚbody©r   Úresponser   r   r   Útest_simpleC   ó   
z*WSGIContainerDummyExecutorTest.test_simplec                 Ã   óV   �| j  ¡  t | j |  d¡¡| j |  d¡¡¡I d H }|D ]	}|  |jd¡ qd S )Nr   r%   ©	r   ÚresetÚasyncioÚgatherÚhttp_clientr3   Úget_urlr4   r5   ©r   ÚrespsÚrespr   r   r   Útest_concurrent_barrierG   ó   €

þÿz6WSGIContainerDummyExecutorTest.test_concurrent_barrierc                 Ã   r:   )Nr   s   ok broken barrierr;   rA   r   r   r   Ú!test_concurrent_streaming_barrierQ   rE   z@WSGIContainerDummyExecutorTest.test_concurrent_streaming_barrierN©r+   r,   r-   r   r8   r   rD   rF   r   r   r   r   r/   ?   s    
	r/   c                   @   r.   )
ÚWSGIContainerThreadPoolTestc                 C   s
   t j ¡ S r   )Ú
concurrentÚfuturesÚThreadPoolExecutorr
   r   r   r   r   ]   s   
z(WSGIContainerThreadPoolTest.get_executorc                 C   r0   r1   r2   r6   r   r   r   r8   `   r9   z'WSGIContainerThreadPoolTest.test_simplec                 Ã   ó\   �| j  ¡  t | j |  d¡¡| j |  d¡¡¡I d H }|  ddgtdd„ |D ƒƒ¡ d S )Nr   ó   ok 0ó   ok 1c                 S   ó   g | ]}|j ‘qS r   ©r5   ©Ú.0rC   r   r   r   Ú
<listcomp>k   ó    zGWSGIContainerThreadPoolTest.test_concurrent_barrier.<locals>.<listcomp>©	r   r<   r=   r>   r?   r3   r@   r4   Úsorted©r   rB   r   r   r   rD   d   ó   €

þ"z3WSGIContainerThreadPoolTest.test_concurrent_barrierc                 Ã   rL   )Nr   rM   rN   c                 S   rO   r   rP   rQ   r   r   r   rS   t   rT   zQWSGIContainerThreadPoolTest.test_concurrent_streaming_barrier.<locals>.<listcomp>rU   rW   r   r   r   rF   m   rX   z=WSGIContainerThreadPoolTest.test_concurrent_streaming_barrierNrG   r   r   r   r   rH   \   s    
rH   )r=   Úconcurrent.futuresrI   r   Úwsgiref.validater   Útornado.routingr   Útornado.testingr   r   Útornado.wsgir   r   r/   rH   r   r   r   r   Ú<module>   s    3