o
    >h
                     @   s   d dl Z d dlZd dlmZ d dlZd dlZe jddrQd dlm	Z	 ej
jejdk ddej
jdd	d
d Zej
jejdk ddej
jdd	dd ZdS dS )    NUSE_ASYNCIOF)	Component)      zrequires Python 3.5+)reasonT)forbid_global_loopc                    s   t jj| t j_tddddgd  j| d}| t j_t  fdd}t d	|  fd
d}|| I d H  d S )Nws://localhost:12/bogus   皙?urlmax_retriesmax_retry_delay
transportsloopc                           td tj_d S Nz	timed outset_exceptionAssertionErrortxaioconfigr    finished	orig_loopr   /var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/wamp/test/test_wamp_component_aio.pyfail;      z$test_asyncio_component.<locals>.failg      @c              
      s~   z|    td W n ty, } zdt|vr"td W Y d }~nd }~ww d  tj_ j	d u s=J d S Nzshould get an errorz(Exhausted all transport connect attemptszwrong exception caught)
resultr   r   RuntimeErrorstr
set_resultr   r   r   _done_ffecompr   r   r   r   done@   s   
z$test_asyncio_component.<locals>.done)r   r   r   r   startcreate_future
call_lateradd_done_callback)
event_loopr(   r   r,   r   r*   r   test_asyncio_component$   s$   

r2   c                    s   t jj| t j_G dd dt}| dg d fdd	}tj| d|N || _tdd	d
dgd}|j| d}| t j_ fdd}t 	d
| t 
 fdd}t 	d| fdd}|| I dH  W d   dS 1 sxw   Y  dS )z
        If something connects but then gets aborted, it should still try
        to re-connect (in real cases this could be e.g. wrong path,
        TLS failure, WebSocket handshake failure, etc)
        c                   @   s   e Zd Zdd Zdd ZdS )z1test_asyncio_component_404.<locals>.FakeTransportc                 S      d S Nr   )selfr   r   r   closeY      z7test_asyncio_component_404.<locals>.FakeTransport.closec                 S   r3   r4   r   )r5   datar   r   r   write\   r7   z7test_asyncio_component_404.<locals>.FakeTransport.writeN)__name__
__module____qualname__r6   r9   r   r   r   r   FakeTransportX   s    r=   NFc                    s@    d d u r|  }| d< |  t|fS ttdS )Nr   z"second connection fails completely)connection_mader   create_future_successcreate_future_errorr#   )protocol_factoryserver_hostnamehostportsslprotocol)actual_protocolfake_transportr   r   create_connectionb   s   
z5test_asyncio_component_404.<locals>.create_connectionrI   r   r	   r
   r   r   r   c                      s"    d d ur d  d  d S d S )Nr   )connection_lostr   )rG   r   r   nuke_transport   s   z2test_asyncio_component_404.<locals>.nuke_transportc                      r   r   r   r   r   r   r   r      r    z(test_asyncio_component_404.<locals>.failg      ?c              
      sp   z|     td W n ty, } zdt|vr" td W Y d }~nd }~ww  d  tj_d S r!   )	r"   r   r   r#   r$   r%   r   r   r   r'   r   r   r   r,      s   
z(test_asyncio_component_404.<locals>.done)NNNNF)r   r   r   objectmockpatchrI   r   r-   r/   r.   r0   )r1   r=   rI   r+   r(   rK   r   r,   r   )rG   rH   r   r   r   test_asyncio_component_404M   s6   	
	"rO   )ossysunittest.mockrM   pytestr   environgetautobahn.asyncio.componentr   markskipifversion_infoasyncior2   rO   r   r   r   r   <module>   s   '