o
    pkj                     @   s  d Z ddlZddlmZ ddlZddlmZ ddlZzddlZddl	m
Z ddlmZ ddlmZ dZW n eyO   d	Ze Ze Ze Ze ZY nw dd
lmZ ddlZddlZddlmZ ddlmZ ddlmZ ejjeddZdZej d	ddd Z!efdee" fddZ#de"fddZ$dd Z%dd Z&dd  Z'd!d" Z(d#d$ Z)d%d& Z*d}d'd(Z+d)d* Z,d+d, Z-ej.d-dd.d/d/d0d1gd2Z/d3d4 Z0d5d6 Z1d7d8 Z2d9d: Z3d;d< Z4d=d> Z5d?d@ Z6dAdB Z7dCdD Z8dEdF Z9dGdH Z:dIdJ Z;dKdL Z<d~dMe"dNe=fdOdPZ>eej?j@ejAdQd	dRdSdT ZBeej?j@ejAdQd	dRdUdV ZCeej?j@ejAdQd	dRdWdX ZDeej?j@ejAdQd	dRdYdZ ZEeej?j@ejAdQd	dRd[d\ ZFeej?j@ejAdQd	dRd]d^ ZGeej?j@ejAdQd	dRd_d` ZHdadb ZIdcdd ZJdedf ZKdgdh ZLdidj ZMdkdl ZNdmdn ZOdodp ZPeej?j@ejAdQd	dRdqdr ZQeej?j@ejAdQd	dRdsdt ZReej?j@ejAdQd	dRdudv ZSeej?j@ejAdQd	dRdwdx ZTeej?j@ejAdQd	dRdydz ZUeej?j@edQd	dRd{d| ZVdS )zTests for http retries.    N)Sequence)mock)Response)AsyncAuthorizedSession)StaticCredentialsFT)credentials   )_api_client)errors)typesz(aiohttp is not installed, skipping test.)reason)    i  i  i    )autousec                   c   s    d V  dt _d S )NF)
api_clienthas_aiohttp r   r   d/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/google/genai/tests/client/test_retries.pyreset_has_aiohttp>   s   
r   retried_codesc                    s    fddt ddD S )Nc                    s   g | ]}| vr|qS r   r   ).0coder   r   r   
<listcomp>E   s    z _final_codes.<locals>.<listcomp>d   iX  )ranger   r   r   r   _final_codesD   s   r   r   c                 C   s   t j| dt| iddS )Nstatus-code    )status_codeheaderscontent)httpxr   str)r   r   r   r   _httpx_responseH   s
   
r%   c                  C   sD   t d } t|  ddhksJ | d jdksJ | d s J d S )Nstopreraise   )r   
retry_argssetkeysmax_attempt_number)argsr   r   r   test_retry_args_disabledS   s   
r.   c                  C   s<  t t } t|  h dksJ | d jdksJ | d }|jdks'J |jdks.J |j	dks5J |j
dks<J | d }tD ](}ztjt| J d
 tjyj } z||s`J W Y d }~qBd }~ww t D ]-}z
tjt| W n tjy } z||rJ W Y d }~nd }~ww | d sJ qnd S )N>   r&   waitretryr'   before_sleepr&      r/      r(   <   r0   FExpected APIError to be raised.r'   )r   r)   r   HttpRetryOptionsr*   r+   r,   exp_baseinitialjittermax_RETRIED_CODESr
   APIErrorraise_for_responser%   	predicater   )r-   r/   r0   r   er   r   r   %test_retry_args_enabled_with_defaults[   s4   
r@   c                     s   g   fdd} t jdi tt }z||  J d tjy'   Y nw t dks0J  d  d  t	j
ddks@J  d	  d  t	j
d	dksPJ  d
  d	  t	j
ddks`J  d  d
  t	j
ddkspJ d S )Nc                     s$   t j  }  |  tjtd)Nr   )datetimenowappendr
   r<   r=   r%   )rB   
timestampsr   r   fn   s   

ztest_retry_wait.<locals>.fnFr5   r2   r(   r   )secondsr3   r         r   )tenacityRetryingr   r)   r   r6   r
   r<   lenrA   	timedelta)rF   retryingr   rD   r   test_retry_wait   s       $rO   c                  C   s2  t jdddddddgd} t| }|d jdksJ |d	 }|jdks&J |jdks-J |jdks4J |jdks;J |d
 }dD ](}zt	j
t| J d t	j
yi } z||s_J W Y d }~qAd }~ww tddgD ]&}z
t	j
t| W qp t	j
y } z||rJ W Y d }~qpd }~ww d S )N
   r   g      ?g      ?r   r   attemptsinitial_delay	max_delayr7   r9   http_status_codesr&   r/   r0   )r   r   Fr5   )r   r6   r   r)   r,   r8   r:   r7   r9   r
   r<   r=   r%   r>   r   )optionsr)   r/   r0   r   r?   r   r   r   =test_retry_args_enabled_with_custom_values_are_not_overridden   s@   
rW   c                  C   s   t t } | d }|tdsJ |tdsJ |tds)J |t	ds3J |t
dr=J |tdrFJ d S )Nr0   stalledzread stalledzconnect stalledzconnect refusedzbad urlznot a transport error)r   r)   r   r6   r>   r#   TimeoutExceptionReadTimeoutConnectTimeoutConnectError
InvalidURL
ValueError)r-   r0   r   r   r   .test_retry_args_retries_httpx_transport_errors   s   r_   c                   C   s   t jdtddfddS )Nzgoogle.auth.defaultmagic_tokentest_projectT)return_valueautospec)r   patchr   Credentialsr   r   r   r   _patch_auth_default   s
   rf   c                 C   s$   | pt  } d|i| _d|i| _| S )N	transport)r   HttpOptionsclient_argsasync_client_args)http_optionsrg   async_transportr   r   r   _transport_options   s   

rm   c                  C   s   t jtjd} td| j_tjdddt	| dd}t
  |jdd	i d
}| j  |jd dks3J W d    d S 1 s>w   Y  d S )Nspec   Tra   globalrg   vertexaiprojectlocationrk   GETpathhttp_methodrx   request_dictr   200)r   Mockr#   BaseTransportr%   handle_requestrb   r   BaseApiClientrm   rf   requestassert_called_oncer!   mock_transportclientresponser   r   r   6test_disabled_retries_successful_request_executes_once   s   
"r   c                  C   s   t jtjd} td| j_tjdddt	| dd}t
 5 z|jdd	i d
 J d tjyC } z|jdks9J W Y d }~nd }~ww | j  W d    d S 1 sTw   Y  d S )Nrn   r   Tra   rq   rr   rs   rw   rx   ry   Fr5   )r   r}   r#   r~   r%   r   rb   r   r   rm   rf   r   r
   r<   r   r   r   r   r?   r   r   r   2test_disabled_retries_failed_request_executes_once   s$   "r   r3   r(   g?r   r   rQ   c                  C   s   t jtjd} td| j_tjdddt	t
jtd| dd}t  |jd	d
i d}| j  |jd dks8J W d    d S 1 sCw   Y  d S )Nrn   rp   Tra   rq   retry_optionsrk   rg   rs   rw   rx   ry   r   r|   )r   r}   r#   r~   r%   r   rb   r   r   rm   r   rh   _RETRY_OPTIONSrf   r   r   r!   r   r   r   r   -test_retries_successful_request_executes_once  s    


"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t  |jd
di d}| j  |jd dks<J W d    d S 1 sGw   Y  d S )Nrn   r   rp   Tra   rq   r   r   rs   rw   rx   ry   r   r|   )r   r}   r#   r~   r%   r   side_effectr   r   rm   r   rh   r   rf   r   assert_calledr!   r   r   r   r   0test_retries_failed_request_retries_successfully$  s$   


"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	| dd}t
 $ |jd	d
i tjtdd}| j  |jd dks<J W d    d S 1 sGw   Y  d S )Nrn   r   rp   Tra   rq   rr   rs   rw   rx   r   rz   rx   r{   rk   r   r|   )r   r}   r#   r~   r%   r   r   r   r   rm   rf   r   r   rh   r   r   r!   r   r   r   r   Atest_retries_failed_request_retries_successfully_at_request_level;  s0   	
"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t 5 z|jd
di d J d tjyL } z|jdksBJ W Y d }~nd }~ww | j  W d    d S 1 s]w   Y  d S Nrn   r   r   Tra   rq   r   r   rs   rw   rx   ry   Fr5   )r   r}   r#   r~   r%   r   r   r   r   rm   r   rh   r   rf   r   r
   r<   r   r   r   r   r   r   2test_retries_failed_request_retries_unsuccessfullyX  s.   

"r   c                  C   s   t jtjd} tdf| j_tjdddt	t
jt
jddd| d	d
}t 5 z|jddi d J d tjyM } z|jdksCJ W Y d }~nd }~ww | j  W d    d S 1 s^w   Y  d S )Nrn   r   Tra   rq   r   )rR   r   r   rs   rw   rx   ry   Fr5   )r   r}   r#   r~   r%   r   r   r   r   rm   r   rh   r6   rf   r   r
   r<   r   r   r   r   r   r   5test_retries_failed_request_no_retries_unsuccessfullyr  s0   
"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	| dd}t
 8 z|jd	d
i dtid J d tjyJ } z|jdks@J W Y d }~nd }~ww | j  W d    d S 1 s[w   Y  d S Nrn   r   r   Tra   rq   rr   rs   rw   rx   r   r   Fr5   )r   r}   r#   r~   r%   r   r   r   r   rm   rf   r   r   r
   r<   r   r   r   r   r   r   Ctest_retries_failed_request_retries_unsuccessfully_at_request_level  s6   	"r   c                  C      dt _dd } t|   d S )NFc                     s   t jtjd} td| j_tjdddt	| dd}t
 " |jdd	i d
I d H }| j  |jd dks7J W d    d S 1 sBw   Y  d S )Nrn   rp   Tra   rq   rl   rs   rw   rx   ry   r   r|   )r   r}   r#   AsyncBaseTransportr%   handle_async_requestrb   r   r   rm   rf   async_requestr   r!   r   r   r   r   run  s    
"zItest_async_disabled_retries_successful_request_executes_once.<locals>.runr   r   asyncior   r   r   r   r   <test_async_disabled_retries_successful_request_executes_once  s   r   c                  C   r   )NFc                     s   t jtjd} td| j_tjdddt	| dd}t
 8 z|jdd	i d
I d H  J d tjyG } z|jdks=J W Y d }~nd }~ww | j  W d    d S 1 sXw   Y  d S )Nrn   r   Tra   rq   r   rs   rw   rx   ry   Fr5   )r   r}   r#   r   r%   r   rb   r   r   rm   rf   r   r
   r<   r   r   r   r   r   r   r     s*   "zEtest_async_disabled_retries_failed_request_executes_once.<locals>.runr   r   r   r   r   8test_async_disabled_retries_failed_request_executes_once     r   c                  C   r   )NFc                     s   t jtjd} td| j_tjdddt	t
jtd| dd}t " |jd	d
i dI d H }| j  |jd dks<J W d    d S 1 sGw   Y  d S )Nrn   rp   Tra   rq   r   rk   rl   rs   rw   rx   ry   r   r|   )r   r}   r#   r   r%   r   rb   r   r   rm   r   rh   r   rf   r   r   r!   r   r   r   r   r     s&   


"z@test_async_retries_successful_request_executes_once.<locals>.runr   r   r   r   r   3test_async_retries_successful_request_executes_once  r   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t " |jd
di dI d H }| j  |jd dks@J W d    d S 1 sKw   Y  d S )Nrn   r   rp   Tra   rq   r   r   rs   rw   rx   ry   r   r|   )r   r}   r#   r   r%   r   r   r   r   rm   r   rh   r   rf   r   r   r!   r   r   r   r   r     s*   


"zCtest_async_retries_failed_request_retries_successfully.<locals>.runr   r   r   r   r   6test_async_retries_failed_request_retries_successfully  s   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	| dd}t
 ' |jd	d
i tjtddI d H }| j  |jd dks@J W d    d S 1 sKw   Y  d S )Nrn   r   rp   Tra   rq   r   rs   rw   rx   r   r   r   r|   )r   r}   r#   r   r%   r   r   r   r   rm   rf   r   r   rh   r   r   r!   r   r   r   r   r     s2   	
"zTtest_async_retries_failed_request_retries_successfully_at_request_level.<locals>.runr   r   r   r   r   Gtest_async_retries_failed_request_retries_successfully_at_request_level     r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t 8 z|jd
di dI d H  J d tjyP } z|jdksFJ W Y d }~nd }~ww | j  W d    d S 1 saw   Y  d S Nrn   r   r   Tra   rq   r   r   rs   rw   rx   ry   Fr5   )r   r}   r#   r   r%   r   r   r   r   rm   r   rh   r   rf   r   r
   r<   r   r   r   r   r   r   r   ?  s4   

"zEtest_async_retries_failed_request_retries_unsuccessfully.<locals>.runr   r   r   r   r   8test_async_retries_failed_request_retries_unsuccessfully<  s   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	| dd}t
 = z|jd	d
i tjtddI d H  J d tjyP } z|jdksFJ W Y d }~nd }~ww | j  W d    d S 1 saw   Y  d S Nrn   r   r   Tra   rq   r   rs   rw   rx   r   r   Fr5   )r   r}   r#   r   r%   r   r   r   r   rm   rf   r   r   rh   r   r
   r<   r   r   r   r   r   r   r   `  s8   	
"zVtest_async_retries_failed_request_retries_unsuccessfully_at_request_level.<locals>.runr   r   r   r   r   Itest_async_retries_failed_request_retries_unsuccessfully_at_request_level]     r   status
streamablec                    s`   t jtjd}| |_dt| i|_i |j_d|j	_|r.t  |_
t jdd|j
_t  |_|S )z&Has to return a coroutine hence async.rn   r   testr   rb   )r   r}   aiohttpClientResponser   r$   r!   jsonrb   textr"   	AsyncMockreadline	MagicMockrelease)r   r   r   r   r   r   _aiohttp_async_response  s   

r   r   )rc   c                    "   dt _ fdd}t|  d S )NTc                     sx   t d _tjdddd} t ! | jddi dI d H }   |jd	 d
ks*J W d    d S 1 s5w   Y  d S )Nrp   Tra   rq   rt   ru   rv   rw   rx   ry   r   r|   )r   rb   r   r   rf   r   r   r!   r   r   mock_requestr   r   r     s   
"zKtest_aiohttp_disabled_retries_successful_request_executes_once.<locals>.runr   r   r   r   r   r   >test_aiohttp_disabled_retries_successful_request_executes_once  s   r   c                    r   )NTc                     s   t d _tjdddd} t 7 z| jddi dI d H  J d
 tjy; } z|jdks1J W Y d }~nd }~ww  	  W d    d S 1 sKw   Y  d S )Nr   Tra   rq   r   rw   rx   ry   Fr5   )
r   rb   r   r   rf   r   r
   r<   r   r   r   r?   r   r   r   r     s&   

"zGtest_aiohttp_disabled_retries_failed_request_executes_once.<locals>.runr   r   r   r   r   :test_aiohttp_disabled_retries_failed_request_executes_once     r   c                    r   )NTc                     s   t d _tjdddttjtddd} t ! | j	dd	i d
I d H } 
  |jd dks2J W d    d S 1 s=w   Y  d S )Nrp   Tra   rq   r   rk   rs   rw   rx   ry   r   r|   )r   rb   r   r   rm   r   rh   r   rf   r   r   r!   r   r   r   r   r     s"   

	"zBtest_aiohttp_retries_successful_request_executes_once.<locals>.runr   r   r   r   r   5test_aiohttp_retries_successful_request_executes_once  r   r   c                    r   )NTc               	      s   t dt df _tjdddttjtddidd	d
} t ! | j	ddi dI d H } 
  |jd dks9J W d    d S 1 sDw   Y  d S )Nr   rp   Tra   rq   	trust_envFr   rj   r   rs   rw   rx   ry   r   r|   )r   r   r   r   rm   r   rh   r   rf   r   r   r!   r   r   r   r   r     s,   "zEtest_aiohttp_retries_failed_request_retries_successfully.<locals>.runr   r   r   r   r   8test_aiohttp_retries_failed_request_retries_successfully  s   r   c                    r   )NTc                     s   t dt df _tjdddd} t & | jddi tjtd	d
I d H } 	  |j
d dks3J W d    d S 1 s>w   Y  d S )Nr   rp   Tra   rq   r   rw   rx   r   r   r   r|   )r   r   r   r   rf   r   r   rh   r   r   r!   r   r   r   r   r     s*   "zVtest_aiohttp_retries_failed_request_retries_successfully_at_request_level.<locals>.runr   r   r   r   r   Itest_aiohttp_retries_failed_request_retries_successfully_at_request_level  s   	r   c                    r   )NTc                     s   t dt df _tjdddttjtddidd	d
} t 7 z| j	ddi dI d H  J d t
jyJ } z|jdks@J W Y d }~nd }~ww    W d    d S 1 sZw   Y  d S )Nr   r   Tra   rq   r   Fr   r   rs   rw   rx   ry   r5   )r   r   r   r   rm   r   rh   r   rf   r   r
   r<   r   r   r   r   r   r   r   ,  s6   
"zGtest_aiohttp_retries_failed_request_retries_unsuccessfully.<locals>.runr   r   r   r   r   :test_aiohttp_retries_failed_request_retries_unsuccessfully'  s   r   c                    r   )NTc                     s   t dt df _tjdddd} t : z| jddi d	tid
I d H  J d tjyB } z|j	dks8J W Y d }~nd }~ww  
  W d    d S 1 sRw   Y  d S )Nr   r   Tra   rq   r   rw   rx   r   r   Fr5   )r   r   r   r   rf   r   r   r
   r<   r   r   r   r   r   r   r   V  s0   
"zXtest_aiohttp_retries_failed_request_retries_unsuccessfully_at_request_level.<locals>.runr   r   r   r   r   Ktest_aiohttp_retries_failed_request_retries_unsuccessfully_at_request_levelK  s   	r   c                  C   s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t " |jd
di d}t| | j  | jjdks?J W d    d S 1 sJw   Y  d S )Nrn   r   rp   Tra   rq   r   r   rs   rw   rx   ry   r3   )r   r}   r#   r~   r%   r   r   r   r   rm   r   rh   r   rf   request_streamedlistr   
call_countr   r   streamr   r   r   9test_retries_streamed_failed_request_retries_successfullyu  s*   


"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	| dd}t
 ' |jd	d
i tjtdd}t| | j  | jjdks?J W d    d S 1 sJw   Y  d S )Nrn   r   rp   Tra   rq   rr   rs   rw   rx   r   r   r3   )r   r}   r#   r~   r%   r   r   r   r   rm   rf   r   r   rh   r   r   r   r   r   r   r   r   Jtest_retries_streamed_failed_request_retries_successfully_at_request_level  s.   	

"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t 9 z|jd
di d}t| J d tjyP } z|jdksFJ W Y d }~nd }~ww | j  W d    d S 1 saw   Y  d S r   )r   r}   r#   r~   r%   r   r   r   r   rm   r   rh   r   rf   r   r   r
   r<   r   r   r   r   r   r?   r   r   r   ;test_retries_streamed_failed_request_retries_unsuccessfully  s4   

"r   c                  C   s   t jtjd} tdtdf| j_tjdddt	| dd}t
 < z|jd	d
i dtid}t| J d tjyN } z|jdksDJ W Y d }~nd }~ww | j  W d    d S 1 s_w   Y  d S r   )r   r}   r#   r~   r%   r   r   r   r   rm   rf   r   r   r   r
   r<   r   r   r   r   r   r   Ltest_retries_streamed_failed_request_retries_unsuccessfully_at_request_level  s8   	"r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t + |jd
di dI d H }|2 z3 d H W }q46 | j  | jjdksIJ W d    d S 1 sTw   Y  d S )Nrn   r   rp   Tra   rq   r   r   rs   rw   rx   ry   r3   )r   r}   r#   r   r%   r   r   r   r   rm   r   rh   r   rf   async_request_streamedr   r   r   r   r   _r   r   r   r     s0   


"zLtest_async_retries_streamed_failed_request_retries_successfully.<locals>.runr   r   r   r   r   ?test_async_retries_streamed_failed_request_retries_successfully  s   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	| dd}t
 0 |jd	d
i tjtddI d H }|2 z3 d H W }q46 | j  | jjdksIJ W d    d S 1 sTw   Y  d S )Nrn   r   rp   Tra   rq   r   rs   rw   rx   r   r   r3   )r   r}   r#   r   r%   r   r   r   r   rm   rf   r   r   rh   r   r   r   r   r   r   r   r     s4   	

"z]test_async_retries_streamed_failed_request_retries_successfully_at_request_level.<locals>.runr   r   r   r   r   Ptest_async_retries_streamed_failed_request_retries_successfully_at_request_level
  r   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	t
jtd| dd	}t B z|jd
di dI d H }|2 z3 d H W }q56 J d tjyZ } z|jdksPJ W Y d }~nd }~ww | j  W d    d S 1 skw   Y  d S r   )r   r}   r#   r   r%   r   r   r   r   rm   r   rh   r   rf   r   r
   r<   r   r   r   r   r   r   r?   r   r   r   r   /  s:   

"zNtest_async_retries_streamed_failed_request_retries_unsuccessfully.<locals>.runr   r   r   r   r   Atest_async_retries_streamed_failed_request_retries_unsuccessfully,  r   r   c                  C   r   )NFc                     s   t jtjd} tdtdf| j_tjdddt	| dd}t
 G z|jd	d
i tjtddI d H }|2 z3 d H W }q56 J d tjyZ } z|jdksPJ W Y d }~nd }~ww | j  W d    d S 1 skw   Y  d S r   )r   r}   r#   r   r%   r   r   r   r   rm   rf   r   r   rh   r   r
   r<   r   r   r   r   r   r   r   R  s>   	
"z_test_async_retries_streamed_failed_request_retries_unsuccessfully_at_request_level.<locals>.runr   r   r   r   r   Rtest_async_retries_streamed_failed_request_retries_unsuccessfully_at_request_levelO  s   r   c                    r   )NTc                     s   t dt dddf _tjdddttjtddd	} t ) | j	d
di dI d H }|2 z3 d H W }q-6  
   jdks@J W d    d S 1 sKw   Y  d S )Nr   rp   Tr   ra   rq   r   r   rs   rw   rx   ry   r3   )r   r   r   r   rm   r   rh   r   rf   r   r   r   r   r   r   r   r   r   r   ~  s,   

	"zNtest_aiohttp_retries_streamed_failed_request_retries_successfully.<locals>.runr   r   r   r   r   Atest_aiohttp_retries_streamed_failed_request_retries_successfullyw  s   r   c                    r   )NTc               	      s   t dt dddf _tjdddd} t 1 | jdd	i tjtd
diddI d H }|2 z3 d H W }q-6  	   j
dks@J W d    d S 1 sKw   Y  d S )Nr   rp   Tr   ra   rq   r   rw   rx   r   Fr   r   r3   )r   r   r   r   rf   r   r   rh   r   r   r   r   r   r   r   r     s2   
	"z_test_aiohttp_retries_streamed_failed_request_retries_successfully_at_request_level.<locals>.runr   r   r   r   r   Rtest_aiohttp_retries_streamed_failed_request_retries_successfully_at_request_level  s   r   c                    r   )NTc                     s   t dt df _tjdddttjtddd} t A z| j	d	d
i dI d H }|2 z3 d H W }q,6 J d t
jyQ } z|jdksGJ W Y d }~nd }~ww    W d    d S 1 saw   Y  d S )Nr   r   Tra   rq   r   r   rs   rw   rx   ry   Fr5   )r   r   r   r   rm   r   rh   r   rf   r   r
   r<   r   r   r   r   r   r?   r   r   r   r     s6   
	
"zPtest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully.<locals>.runr   r   r   r   r   Ctest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully  s   	r   c                    r   )NTc                     s   t dt df _tjdddtjddidd	} t D z| jd
di dtidI d H }|2 z3 d H W }q.6 J d t	j
yS } z|jdksIJ W Y d }~nd }~ww    W d    d S 1 scw   Y  d S )Nr   r   Tra   rq   r   F)rj   rs   rw   rx   r   r   r5   )r   r   r   r   r   rh   rf   r   r   r
   r<   r   r   r   r   r   r   r     s<   	
"zatest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully_at_request_level.<locals>.runr   r   r   r   r   Ttest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully_at_request_level  s   r   c                    r   )NTc               
      s   t jt jddddd d d tdtdf _tjdddd	} t	 ! | j
d
di dI d H }   |jd dks;J W d    d S 1 sFw   Y  d S )N	localhostP   FT)connection_keyos_errorrp   ra   rq   r   rw   rx   ry   r   r|   )r   ClientConnectorErrorclient_reqrepConnectionKeyOSErrorr   r   r   r   rf   r   r   r!   r   r   r   r   r     s*   "zMtest_aiohttp_retries_client_connector_error_retries_successfully.<locals>.runr   r   r   r   r   @test_aiohttp_retries_client_connector_error_retries_successfully  s   	r   c                    r   )NTc                     s,  t dI d H } t dI d H }tjtd}| |_tjtd}||_||g _tjdddtj	t
dd}tjd	dd
R t 6 z|jddi dI d H  J d tjyh } z|jdks^J W Y d }~nd }~ww    W d    n1 sww   Y  W d    d S W d    d S 1 sw   Y  d S )Nr   r   rn   Tra   rq   r   rs   z1google.auth.transport.mtls.should_use_client_certr   rw   rx   ry   Fr5   )r   r   r}   AsyncAuthorizedSessionResponse	_responser   r   r   r   rh   r   rd   rf   r   r
   r<   r   r   )res429res504mock_auth_res429mock_auth_res504r   r?   r   r   r   r   >  sD   


"zLtest_aiohttp_retries_failed_request_retries_unsuccessfully_mtls.<locals>.runr   r   r   r   r   ?test_aiohttp_retries_failed_request_retries_unsuccessfully_mtls7  s   &r   )NNN)F)W__doc__r   collections.abcr   rA   unittestr   pytestr   !google.auth.aio.transport.aiohttpr   r   "google.auth.aio.transport.sessionsr   google.auth.aio.credentialsr   AIOHTTP_NOT_INSTALLEDImportErrorr   google.oauth2r   r#   rJ    r	   r   r
   r   markskipifrequires_aiohttpr;   fixturer   intr   r%   r.   r@   rO   rW   r_   rf   rm   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   rd   objectClientSessionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   


'#


!"!% "$" "#( ##&"