
    hj              	          d Z ddlZddlmZ ddlZ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 dZnI# e$ rA d	Z ej                    Z ej                    Z ej                    Z ej                    ZY nw xY 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                            ed          ZdZ ej         d	          d             Z!efdee"         fdZ#de"fdZ$d Z%d Z&d Z'd Z(d Z)d Z*dNdZ+d Z,d  Z- ej.        d!dd"d#d#d$d%g&          Z/d' Z0d( Z1d) Z2d* Z3d+ Z4d, Z5d- Z6d. Z7d/ Z8d0 Z9d1 Z:d2 Z;d3 Z<dOd4e"d5e=fd6Z>eej?        @                    ejA        d7d	8          d9                         ZBeej?        @                    ejA        d7d	8          d:                         ZCeej?        @                    ejA        d7d	8          d;                         ZDeej?        @                    ejA        d7d	8          d<                         ZEeej?        @                    ejA        d7d	8          d=                         ZFeej?        @                    ejA        d7d	8          d>                         ZGeej?        @                    ejA        d7d	8          d?                         ZHd@ ZIdA ZJdB ZKdC ZLdD ZMdE ZNdF ZOdG ZPeej?        @                    ejA        d7d	8          dH                         ZQeej?        @                    ejA        d7d	8          dI                         ZReej?        @                    ejA        d7d	8          dJ                         ZSeej?        @                    ejA        d7d	8          dK                         ZTeej?        @                    ejA        d7d	8          dL                         ZUeej?        @                    ed7d	8          dM                         ZVdS )Pz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               #   *   K   d V  dt           _        d S )NF)
api_clienthas_aiohttp     j/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/google/genai/tests/client/test_retries.pyreset_has_aiohttpr   >   s      %%% *r   retried_codesc                 <      fdt          dd          D             S )Nc                     g | ]}|v|	S r   r   ).0coder   s     r   
<listcomp>z _final_codes.<locals>.<listcomp>E   s#    	H	H	H4d-.G.G$.G.G.Gr   d   iX  )range)r   s   `r   _final_codesr!   D   s%    	H	H	H	H5c??	H	H	HHr   r   c                 N    t          j        | dt          |           id          S )Nstatus-coder   )status_codeheaderscontent)httpxr   str)r   s    r   _httpx_responser)   H   s/    	c$ii(
 
 
 r   c                      t          j        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)argss    r   test_retry_args_disabledr3   S   sf    		t	$	$$	TYY[[		fi0	0	0	0	0	f	(A	-	-	-	-	ir   c                  .   t          j        t          j                              } 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    sJ |j
        dk    sJ | d         }t          D ]k}	 t          j                            t          |                     J d
            # t          j        $ r!}|                    |          sJ Y d }~dd }~ww xY wt#                      D ]m}	 t          j                            t          |                     n3# t          j        $ r!}|                    |          rJ Y d }~nd }~ww xY w| d         sJ nd S )N>   r+   waitretryr,   before_sleepr+      r5      r-   <   r6   FExpected APIError to be raised.r,   )r   r.   r   HttpRetryOptionsr/   r0   r1   exp_baseinitialjittermax_RETRIED_CODESr   APIErrorraise_for_responser)   	predicater!   )r2   r5   r6   r   es        r   %test_retry_args_enabled_with_defaultsrF   [   s   		u577	8	8$	TYY[[		    
 
 
 
 
f	(A	-	-	-	-	f$	!															R
w-%    d o(()>)>???55555?      __Q  nn  d$o(()>)>????? $ $ $##########$ 	? s0   06C&&D5DD*,EF&FFc                  N   g fd} t          j        di t          j        t	          j                              }	  ||            J d            # t          j        $ r Y nw xY wt                    dk    sJ d         d         z
  t          j
        d          k    sJ d         d         z
  t          j
        d          k    sJ d	         d         z
  t          j
        d
          k    sJ d
         d	         z
  t          j
        d          k    sJ d S )Nc                      t           j                                         }                     |            t          j                            t          d                    )Nr   )datetimenowappendr   rB   rC   r)   )rJ   
timestampss    r   fnztest_retry_wait.<locals>.fn   sI    




!
!Cc
/
,
,_S-A-A
B
BBr   Fr;   r8   r-   r   )secondsr9   r	         r   )tenacityRetryingr   r.   r   r<   r   rB   lenrI   	timedelta)rM   retryingrL   s     @r   test_retry_waitrV      sm   *C C C C C
   e46677 (	HRLLL33333	 	 	 	D	 
ZA					AA	&(*<Q*G*G*G	G	G	G	G	AA	&(*<Q*G*G*G	G	G	G	G	AA	&(*<Q*G*G*G	G	G	G	G	AA	&(*<Q*G*G*G	G	G	G	G	G	Gs   A A%$A%c            	         t          j        dddddddg          } t          j        |           }|d         j        dk    sJ |d	         }|j        dk    sJ |j        dk    sJ |j        dk    sJ |j        dk    sJ |d
         }dD ]k}	 t          j
                            t          |                     J d            # t          j
        $ r!}|                    |          sJ Y d }~dd }~ww xY wt          ddg          D ]b}	 t          j
                            t          |                     0# t          j
        $ r!}|                    |          rJ Y d }~[d }~ww xY wd S )N
   r   g      ?g      ?r   r   attemptsinitial_delay	max_delayr=   r?   http_status_codesr+   r5   r6   )r   r   Fr;   )r   r<   r   r.   r1   r>   r@   r=   r?   r   rB   rC   r)   rD   r!   )optionsr.   r5   r6   r   rE   s         r   =test_retry_args_enabled_with_custom_values_are_not_overriddenr_      s   "c
  ' $W--*	F		."	4	4	4	4	F	$						S	#									
W
%    d o(()>)>???55555?      __Q  C:&& $ $d$o(()>)>????? $ $ $##########$	$ $s0   6CC3C..C3
,D77E'E""E'c                  B   t          j        t          j                              } | d         }|                    t          j        d                    sJ |                    t          j        d                    sJ |                    t          j        d                    sJ |                    t          j	        d                    sJ |                    t          j
        d                    rJ |                    t          d                    rJ d S )Nr6   stalledzread stalledzconnect stalledzconnect refusedzbad urlznot a transport error)r   r.   r   r<   rD   r'   TimeoutExceptionReadTimeoutConnectTimeoutConnectError
InvalidURL
ValueError)r2   r6   s     r   .test_retry_args_retries_httpx_transport_errorsrh      s     
	u577	8	8$
w-%	/	::	;	;;;;	*>::	;	;;;;	-.?@@	A	AAAA	+,=>>	?	???? __U-i8899999__Z(?@@AAAAAAAr   c                  X    t          j        dt          j        d          dfd          S )Nzgoogle.auth.defaultmagic_tokentest_projectT)return_valueautospec)r   patchr   Credentialsr   r   r   _patch_auth_defaultrp      s4    	+M::NK
 
 
 r   c                 T    | pt          j                    } d|i| _        d|i| _        | S )N	transport)r   HttpOptionsclient_argsasync_client_args)http_optionsrr   async_transports      r   _transport_optionsrx      s5    4!2!4!4,)95,$/#A, 	r   c                     t          j        t          j                  } t	          d          | j        _        t          j        dddt          |                     }t                      5  |                    dd	i 
          }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nspec   Trk   globalrr   vertexaiprojectlocationrv   GETpathhttp_methodr   request_dictr#   200)r   Mockr'   BaseTransportr)   handle_requestrl   r   BaseApiClientrx   rp   requestassert_called_oncer%   mock_transportclientresponses      r   6test_disabled_retries_successful_request_executes_oncer      s   9%"5666./>s/C/C.,#%???	  &  4 4~~%f2~NNH!44666M*e333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   -AC  CCc                     t          j        t          j                  } t	          d          | j        _        t          j        dddt          |                     }t                      5  	 |                    dd	i 
           J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S )Nrz   r   Trk   r}   r~   r   r   r   r   Fr;   )r   r   r'   r   r)   r   rl   r   r   rx   rp   r   r   rB   r   r   r   r   rE   s      r   2test_disabled_retries_failed_request_executes_oncer      sE   9%"5666./>s/C/C.,#%???	  &  7 7nnV"nEEE55555?   Vs]]]]]]]]]!446667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s6   -C /"BB7 B2-C 2B77C  C$'C$r9   r-   g?r   r   rY   c            
         t          j        t          j                  } t	          d          | j        _        t          j        dddt          t          j        t                    |                     }t                      5  |                    d	d
i           }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r|   Trk   r}   retry_optionsrv   rr   r   r   r   r   r#   r   )r   r   r'   r   r)   r   rl   r   r   rx   r   rs   _RETRY_OPTIONSrp   r   r   r%   r   s      r   -test_retries_successful_request_executes_oncer     s*   9%"5666./>s/C/C.,#%(~FFF"  	  &  4 4~~%f2~NNH!44666M*e333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   ACC Cc            
         t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  |                    d
di           }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r#   r   )r   r   r'   r   r)   r   side_effectr   r   rx   r   rs   r   rp   r   assert_calledr%   r   s      r   0test_retries_failed_request_retries_successfullyr   $  s<   9%"5666.cc/.+
 #%(~FFF"  	  &  4 4~~%f2~NNH!//111M*e333334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   AC((C,/C,c            	         t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  |                    d	d
i t          j        t                              }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r~   r   r   r   r   r   r   r   rv   r#   r   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   rs   r   r   r%   r   s      r   Atest_retries_failed_request_retries_successfully_at_request_levelr   ;  sO   9%"5666.cc/.+
 #%"  	  &  
4 
4~~&(
 
 
	   H !//111M*e33333
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4 
4s   <AC((C,/C,c            
      *   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  	 |                    d
di            J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S Nrz   r   r   Trk   r}   r   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   r   r   rB   r   r   r   s      r   2test_retries_failed_request_retries_unsuccessfullyr   X  so   9%"5666.cc/.+
 #%(~FFF"  	  &  2 2nnV"nEEE55555?   Vs]]]]]]]]]!//1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 26   D"B99CCDCDDDc                  *   t          j        t          j                  } t	          d          f| j        _        t          j        dddt          t          j        t          j        d                    | 	          
          }t                      5  	 |                    ddi            J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S )Nrz   r   Trk   r}   r   )rZ   r   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r<   rp   r   r   rB   r   r   r   s      r   5test_retries_failed_request_no_retries_unsuccessfullyr   r  s{   9%"5666.c/.+ #%(!2A>>>   #	  	
 
 
&  2 2nnV"nEEE55555?   Vs]]]]]]]]]!//1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2r   c                     t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  	 |                    d	d
i dt          i           J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S Nrz   r   r   Trk   r}   r~   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   r   rB   r   r   r   s      r   Ctest_retries_failed_request_retries_unsuccessfully_at_request_levelr     st   9%"5666.cc/.+
 #%"  	  &  2 2	nn'8	     65555?   Vs]]]]]]]]]!//1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s6   <C7>*B((C7C	C7	CC77C;>C;c                  \    dt           _        d } t          j         |                        d S )NFc                    K   t          j        t          j                  } t	          d          | j        _        t          j        dddt          |                     }t                      5  |                    dd	i 
           d {V }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r|   Trk   r}   rw   r   r   r   r   r#   r   )r   r   r'   AsyncBaseTransportr)   handle_async_requestrl   r   r   rx   rp   async_requestr   r%   r   s      r   runzItest_async_disabled_retries_successful_request_executes_once.<locals>.run  s@     YE$<===N7Fs7K7KN'4%'GGG	  F 
		 6 6++&r ,        h )<<>>>m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   /ACCCr   r   asyncior   r   s    r   <test_async_disabled_retries_successful_request_executes_oncer     s7     *6 6 6$ 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc                    K   t          j        t          j                  } t	          d          | j        _        t          j        dddt          |                     }t                      5  	 |                    dd	i 
           d {V  J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S )Nrz   r   Trk   r}   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   rl   r   r   rx   rp   r   r   rB   r   r   r   s      r   r   zEtest_async_disabled_retries_failed_request_executes_once.<locals>.run  su     YE$<===N7Fs7K7KN'4%'GGG	  F 
		 ? ?""F # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}})<<>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s6   /C(1(BB?(B:5C(:B??C((C,/C,r   r   s    r   8test_async_disabled_retries_failed_request_executes_oncer     s7     *? ? ?* 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            
        K   t          j        t          j                  } t	          d          | j        _        t          j        dddt          t          j        t                    |                     }t                      5  |                    d	d
i            d {V }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r|   Trk   r}   r   rv   rw   r   r   r   r   r#   r   )r   r   r'   r   r)   r   rl   r   r   rx   r   rs   r   rp   r   r   r%   r   s      r   r   z@test_async_retries_successful_request_executes_once.<locals>.run  sX     YE$<===N7Fs7K7KN'4%'*HHH*
 
 
	  F 
		 6 6++&r ,        h )<<>>>m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   AC!!C%(C%r   r   s    r   3test_async_retries_successful_request_executes_oncer     s7     *6 6 6* 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            
        K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  |                    d
di            d {V }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r#   r   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   r   r   r%   r   s      r   r   zCtest_async_retries_failed_request_retries_successfully.<locals>.run  sj     YE$<===N7N'3
 %'*HHH*
 
 
	  F 
		 6 6++&r ,        h )77999m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   AC00C47C4r   r   s    r   6test_async_retries_failed_request_retries_successfullyr     s7     *6 6 60 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            	        K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  |                    d	d
i t          j        t                               d {V }| j                                         |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r#   r   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   rs   r   r   r%   r   s      r   r   zTtest_async_retries_failed_request_retries_successfully_at_request_level.<locals>.run  ss     YE$<===N7N'3
 %'*
 
 
	  F 
		 
6 
6++(*  	 ,        h )77999m,55555
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6s   >A$C00C47C4r   r   s    r   Gtest_async_retries_failed_request_retries_successfully_at_request_levelr     s7     *6 6 68 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            
      :  K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  	 |                    d
di            d {V  J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S Nrz   r   r   Trk   r}   r   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   r   r   rB   r   r   r   s      r   r   zEtest_async_retries_failed_request_retries_unsuccessfully.<locals>.run?  s     YE$<===N7N'3
 %'*HHH*
 
 
	  F 
		 : :""F # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}})77999: : : : : : : : : : : : : : : : : :s6   D(CC'C"D"C''DDDr   r   s    r   8test_async_retries_failed_request_retries_unsuccessfullyr   <  s7     *: : :6 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            	      :  K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  	 |                    d	d
i t          j        t                               d {V  J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S Nrz   r   r   Trk   r}   r   r   r   r   r   r   Fr;   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   rs   r   r   rB   r   r   r   s      r   r   zVtest_async_retries_failed_request_retries_unsuccessfully_at_request_level.<locals>.run`  s     YE$<===N7N'3
 %'*
 
 
	  F 
		 : :	""*HHH	 # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}})77999: : : : : : : : : : : : : : : : : :s7   >D ACC'C"D"C''DDDr   r   s    r   Itest_async_retries_failed_request_retries_unsuccessfully_at_request_levelr   ]  7     *: : :: 
+cceer   status
streamablec                 T  K   t          j        t          j                  }| |_        dt          |           i|_        i |j        _        d|j	        _        |rOt          j                    |_
        t          j        d          |j
        _        t          j                    |_        |S )z&Has to return a coroutine hence async.rz   r#   testr   rl   )r   r   aiohttpClientResponser   r(   r%   jsonrl   textr&   	AsyncMockreadline	MagicMockrelease)r   r   r   s      r   _aiohttp_async_responser     s      YG2333((/#S[[1(!(-%(- (y{{H $C @ @ @H~''H	/r   r   )rm   c                 b     dt           _         fd}t          j         |                       d S )NTc                  <  K   t          d          _        t          j        ddd          } t	                      5  |                     ddi            d {V }                                 |j        d	         d
k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr|   Trk   r}   r   r   r   r   r   r   r#   r   )r   rl   r   r   rp   r   r   r%   r   r   mock_requests     r   r   zKtest_aiohttp_disabled_retries_successful_request_executes_once.<locals>.run  s      7 < <L%  F 
		 6 6++&r ,        h %%'''m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   ABBBr   r   r   s   ` r   >test_aiohttp_disabled_retries_successful_request_executes_oncer     sD    
  *6 6 6 6 6  
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                  |  K   t          d          _        t          j        ddd          } t	                      5  	 |                     ddi            d {V  J d
            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w	                                 d d d            d S # 1 swxY w Y   d S )Nr   Trk   r}   r   r   r   r   Fr;   )
r   rl   r   r   rp   r   r   rB   r   r   r   rE   r   s     r   r   zGtest_aiohttp_disabled_retries_failed_request_executes_once.<locals>.run  sM      7 < <L%  F 
		 ( (""F # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}}%%'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s4   B1(A''B6BB1BB11B58B5r   r   s   ` r   :test_aiohttp_disabled_retries_failed_request_executes_oncer     sD      *( ( ( ( (& 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc            
        K   t          d          _        t          j        dddt	          t          j        t                                        } t                      5  | 	                    dd	i 
           d {V }
                                 |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr|   Trk   r}   r   rv   r   r   r   r   r#   r   )r   rl   r   r   rx   r   rs   r   rp   r   r   r%   r   s     r   r   zBtest_aiohttp_retries_successful_request_executes_once.<locals>.run  s;      7 < <L%'*HHH
 
 
	  F 
		 6 6++&r ,        h %%'''m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   $AB88B<?B<r   r   s   ` r   5test_aiohttp_retries_successful_request_executes_oncer     sD      *6 6 6 6 6& 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          d          t          d          f_        t          j        dddt	          t          j        t          ddi          	          
          } t                      5  | 	                    ddi            d {V }
                                 |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r|   Trk   r}   	trust_envFr   ru   r   r   r   r   r   r#   r   )r   r   r   r   rx   r   rs   r   rp   r   r   r%   r   s     r   r   zEtest_aiohttp_retries_failed_request_retries_successfully.<locals>.run  s\     $$$$ L
 %'*,#."6  
 
 
	
 
 
F 
		 6 6++&r ,        h   """m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   6AC

CCr   r   s   ` r   8test_aiohttp_retries_failed_request_retries_successfullyr     sD      *6 6 6 6 62 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc            	        K   t          d          t          d          f_        t          j        ddd          } t	                      5  |                     ddi t          j        t          	          
           d {V }	                                 |j
        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r|   Trk   r}   r   r   r   r   r   r#   r   )r   r   r   r   rp   r   r   rs   r   r   r%   r   s     r   r   zVtest_aiohttp_retries_failed_request_retries_successfully_at_request_level.<locals>.run  sD     $$$$ L
 %  F 
		 
6 
6++(*  	 ,        h   """m,55555
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6 
6s   AB99B= B=r   r   s   ` r   Itest_aiohttp_retries_failed_request_retries_successfully_at_request_levelr     sD      *6 6 6 6 60 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          d          t          d          f_        t          j        dddt	          t          j        t          ddi          	          
          } t                      5  	 | 	                    ddi            d {V  J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w                                 d d d            d S # 1 swxY w Y   d S )Nr   r   Trk   r}   r   Fr   r   r   r   r   r   r;   )r   r   r   r   rx   r   rs   r   rp   r   r   rB   r   r   r   s     r   r   zGtest_aiohttp_retries_failed_request_retries_unsuccessfully.<locals>.run,  s     $$$$ L
 %'*,#."6  
 
 
	
 
 
F 
		 # #""F # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}}  """# # # # # # # # # # # # # # # # # #s6   6C*8(B  C/C<C*CC**C.1C.r   r   s   ` r   :test_aiohttp_retries_failed_request_retries_unsuccessfullyr   '  sD      *# # # # #8 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          d          t          d          f_        t          j        ddd          } t	                      5  	 |                     ddi d	t          i
           d {V  J d            # t          j        $ r}|j	        dk    sJ Y d }~nd }~ww xY w
                                 d d d            d S # 1 swxY w Y   d S )Nr   r   Trk   r}   r   r   r   r   r   Fr;   )r   r   r   r   rp   r   r   r   rB   r   r   r   s     r   r   zXtest_aiohttp_retries_failed_request_retries_unsuccessfully_at_request_level.<locals>.runV  si     $$$$ L
 %  F 
		 # #	"")>:	 # 
 
 	
 	
 	
 	
 	
 	
 	
 	87777_   v}}}}}}}}}  """# # # # # # # # # # # # # # # # # #s6   C0A>>B$BCB$$CCCr   r   s   ` r   Ktest_aiohttp_retries_failed_request_retries_unsuccessfully_at_request_levelr   K  sD      *# # # # #2 
+cceer   c            
         t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  |                    d
di           }t          |           | j                                         | j        j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r9   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   request_streamedlistr   
call_countr   r   streams      r   9test_retries_streamed_failed_request_retries_successfullyr   u  sQ   9%"5666.cc/.+
 #%(~FFF"  	  &  9 9$$R %  F 	LLL!//111(3q888889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s   AC66C:=C:c            	         t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  |                    d	d
i t          j        t                              }t          |           | j                                         | j        j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r~   r   r   r   r   r   r9   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   rs   r   r   r   r   r   s      r   Jtest_retries_streamed_failed_request_retries_successfully_at_request_levelr    sS   9%"5666.cc/.+
 #%"  	  &  	9 	9$$&^DDD	 %  F 	LLL!//111(3q88888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   <A,C66C:=C:c            
      H   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  	 |                    d
di           }t          |           J d            # t           j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   r   r   r   rB   r   r   r   r   r   rE   s       r   ;test_retries_streamed_failed_request_retries_unsuccessfullyr    s   9%"5666.cc/.+
 #%(~FFF"  	  &  	2 	2&&&r '  f 6lll55555?   Vs]]]]]]]]]!//111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s6   D1CC.C)$D)C..DDDc                  &   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  	 |                    d	d
i dt          i          }t          |           J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r'   r   r)   r   r   r   r   rx   rp   r   r   r   r   rB   r   r   r  s       r   Ltest_retries_streamed_failed_request_retries_unsuccessfully_at_request_levelr    s~   9%"5666.cc/.+
 #%"  	  &  2 2
&&'8	 '  f 6lll55555?   Vs]]]]]]]]]!//1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s6   <D>9B77CCDCDD
D
c                  \    dt           _        d } t          j         |                        d S )NFc            
        K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  |                    d
di            d {V }|2 3 d {V }6 | j                                         | j        j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r9   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   async_request_streamedr   r   r   r   r   _s       r   r   zLtest_async_retries_streamed_failed_request_retries_successfully.<locals>.run  s     YE$<===N7N'3
 %'*HHH*
 
 
	  F 
		 A A22&r 3        f         )779990;q@@@@@A A A A A A A A A A A A A A A A A As   !C:8C >.C::C>C>r   r   s    r   ?test_async_retries_streamed_failed_request_retries_successfullyr    s:     *A A A4 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            	        K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  |                    d	d
i t          j        t                               d {V }|2 3 d {V }6 | j                                         | j        j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nrz   r   r|   Trk   r}   r   r   r   r   r   r   r9   )r   r   r'   r   r)   r   r   r   r   rx   rp   r	  r   rs   r   r   r   r
  s       r   r   z]test_async_retries_streamed_failed_request_retries_successfully_at_request_level.<locals>.run  s     YE$<===N7N'3
 %'*
 
 
	  F 
		 
A 
A22(~FFF	 3        f         )779990;q@@@@@
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
A 
As   >:C:8C >.C::C>C>r   r   s    r   Ptest_async_retries_streamed_failed_request_retries_successfully_at_request_levelr  
  s:     *A A A8 
+cceer   c                  \    dt           _        d } t          j         |                        d S )NFc            
      P  K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          t          j        t                    |           	          }t                      5  	 |                    d
di            d {V }|2 3 d {V }6 J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r'   r   r)   r   r   r   r   rx   r   rs   r   rp   r	  r   rB   r   r   r   r   r   r  rE   s        r   r   zNtest_async_retries_streamed_failed_request_retries_unsuccessfully.<locals>.run/  s     YE$<===N7N'3
 %'*HHH*
 
 
	  F 
		 
: 
:44F 5 
 
 
 
 
 
 
 
  	 	 	 	 	 	 	!
 77777_   v}}}}}}}}})77999
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
:sB   D C9C?CC2C-(D-C22DD"Dr   r   s    r   Atest_async_retries_streamed_failed_request_retries_unsuccessfullyr  ,  r   r   c                  \    dt           _        d } t          j         |                        d S )NFc            	      P  K   t          j        t          j                  } t	          d          t	          d          f| j        _        t          j        dddt          |                     }t                      5  	 |                    d	d
i t          j        t                               d {V }|2 3 d {V }6 J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w| j                                         d d d            d S # 1 swxY w Y   d S r   )r   r   r'   r   r)   r   r   r   r   rx   rp   r	  r   rs   r   r   rB   r   r   r  s        r   r   z_test_async_retries_streamed_failed_request_retries_unsuccessfully_at_request_level.<locals>.runR  s     YE$<===N7N'3
 %'*
 
 
	  F 
		 : :44*HHH	 5 
 
 
 
 
 
 
 
  	 	 	 	 	 	 	!
 77777_   v}}}}}}}}})77999: : : : : : : : : : : : : : : : : :sB   >D 9C9C?CC2C-(D-C22DD"Dr   r   s    r   Rtest_async_retries_streamed_failed_request_retries_unsuccessfully_at_request_levelr  O  s7     *: : :> 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc            
        K   t          d          t          dd          f_        t          j        dddt	          t          j        t                              	          } t                      5  | 	                    d
di            d {V }|2 3 d {V }6 
                                 j        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r|   Tr   rk   r}   r   r   r   r   r   r   r9   )r   r   r   r   rx   r   rs   r   rp   r	  r   r   r   r   r  r   s      r   r   zNtest_aiohttp_retries_streamed_failed_request_retries_successfully.<locals>.run~  s}     $$555 L
 %'*HHH
 
 
	  F 
		 * *22&r 3        f           """$)))))* * * * * * * * * * * * * * * * * *s   5!CB$CCCr   r   s   ` r   Atest_aiohttp_retries_streamed_failed_request_retries_successfullyr  w  sD    
  ** * * * *0 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          d          t          dd          f_        t          j        ddd          } t	                      5  |                     dd	i t          j        t          d
di                     d {V }|2 3 d {V }6 	                                 j
        dk    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r|   Tr  rk   r}   r   r   r   r   Fr   r   r9   )r   r   r   r   rp   r	  r   rs   r   r   r   r  s      r   r   z_test_aiohttp_retries_streamed_failed_request_retries_successfully_at_request_level.<locals>.run  s|     $$555 L
 %  F 
		 * *22(*!,e 4  	 3        f           """$)))))* * * * * * * * * * * * * * * * * *s   =CB$CC
Cr   r   s   ` r   Rtest_aiohttp_retries_streamed_failed_request_retries_successfully_at_request_levelr    sD    
  ** * * * *6 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc            
        K   t          d          t          d          f_        t          j        dddt	          t          j        t                                        } t                      5  	 | 	                    d	d
i            d {V }|2 3 d {V }6 J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w                                 d d d            d S # 1 swxY w Y   d S )Nr   r   Trk   r}   r   r   r   r   r   r   Fr;   )r   r   r   r   rx   r   rs   r   rp   r	  r   rB   r   r   r   r   r  rE   r   s       r   r   zPtest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully.<locals>.run  s     $$$$ L
 %'*HHH
 
 
	  F 
		 
# 
#44F 5 
 
 
 
 
 
 
 
  	 	 	 	 	 	 	!
 77777_   v}}}}}}}}}  """
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
# 
#sB   3C25 B(BB((C7C	C2	CC22C69C6r   r   s   ` r   Ctest_aiohttp_retries_streamed_failed_request_retries_unsuccessfullyr"    sD      *# # # # #6 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc            	        K   t          d          t          d          f_        t          j        dddt	          j        ddi          	          } t                      5  	 |                     d
di dt          i           d {V }|2 3 d {V }6 J d            # t          j
        $ r}|j        dk    sJ Y d }~nd }~ww xY w                                 d d d            d S # 1 swxY w Y   d S )Nr   r   Trk   r}   r   F)ru   r   r   r   r   r   r;   )r   r   r   r   r   rs   rp   r	  r   r   rB   r   r   r!  s       r   r   zatest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully_at_request_level.<locals>.run  s     $$$$ L
 %&*E2
 
 
	  F 
		 # #44)>:	 5 
 
 
 
 
 
 
 
  	 	 	 	 	 	 	!
 77777_   v}}}}}}}}}  """# # # # # # # # # # # # # # # # # #sB   "C)$(BBBC.C ;C) CC))C-0C-r   r   s   ` r   Ttest_aiohttp_retries_streamed_failed_request_retries_unsuccessfully_at_request_levelr%    sD    
  *# # # # #< 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          j        t           j                            ddddd d d           t                    t          d          f_        t          j        ddd	          } t                      5  | 
                    d
di            d {V }                                 |j        d         dk    sJ 	 d d d            d S # 1 swxY w Y   d S )N	localhostP   FT)connection_keyos_errorr|   rk   r}   r   r   r   r   r#   r   )r   ClientConnectorErrorclient_reqrepConnectionKeyOSErrorr   r   r   r   rp   r   r   r%   r   s     r   r   zMtest_aiohttp_retries_client_connector_error_retries_successfully.<locals>.run  s`     $"0>>RdD$  		
 	
 	
 	 $$ L %  F 
		 6 6++&r ,        h   """m,555556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s   ;ACCCr   r   s   ` r   @test_aiohttp_retries_client_connector_error_retries_successfullyr0    sD      *6 6 6 6 64 
+cceer   c                 b     dt           _         fd}t          j         |                       d S )NTc                    K   t          d           d {V } t          d           d {V }t          j        t                    }| |_        t          j        t                    }||_        ||g_        t          j        dddt          j	        t                              }t          j        d	d
          5  t                      5  	 |                    ddi            d {V  J d            # t          j        $ r}|j        dk    sJ Y d }~nd }~ww xY w                                 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r   rz   Trk   r}   r   r   z1google.auth.transport.mtls.should_use_client_certr   r   r   r   Fr;   )r   r   r   AsyncAuthorizedSessionResponse	_responser   r   r   r   rs   r   rn   rp   r   r   rB   r   r   )res429res504mock_auth_res429mock_auth_res504r   rE   r   s         r   r   zLtest_aiohttp_retries_failed_request_retries_unsuccessfully_mtls.<locals>.run>  sR     *3////////F*3////////F y&DEEE!'y&DEEE!' !12BCL%&(
 
 
	  F 
;$
 
 
 % %    % %	$$f2 %          :9
9
9
9 	 	 	3	""$$$% % % % % % % % % % % % % % %% % % % % % % % % % % % % % % % % %sZ   ?EE(C88DDEDE5EE	EE		EE Er   r   s   ` r   ?test_aiohttp_retries_failed_request_retries_unsuccessfully_mtlsr9  7  sE    
  *$% $% $% $% $%L 
+cceer   )NNN)F)W__doc__r   collections.abcr   rI   unittestr   pytestr   !google.auth.aio.transport.aiohttpr   r3  "google.auth.aio.transport.sessionsr   google.auth.aio.credentialsr   AIOHTTP_NOT_INSTALLEDImportErrorr   google.oauth2r   r'   rQ    r
   r   r   r   markskipifrequires_aiohttprA   fixturer   intr!   r)   r3   rF   rV   r_   rh   rp   rx   r   r   r<   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolr   rn   objectClientSessionr   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r"  r%  r0  r9  r   r   r   <module>rM     s       $ $ $ $ $ $        ,...ZZZZZZGGGGGG;;;;;; , , ,DN'#14>#3#3 $dn&&)4>++, & % % % % %   ) ) ) ) ) )             ;%%"L &   
 ! ! !
 1? I I I I I I#      $ $ $NH H H2 $  $  $FB B B"     4 4 4"7 7 7( ('Cj  4 4 4(4 4 4.4 4 4:2 2 242 2 262 2 2B  0  6  6  <  D  B     J # 4     7()dCC  DC 0 7()dCC  DC 2 7()dCC  DC 2 7()dCC  DC >    
   @ 7()dCC  DC D    
   H9 9 949 9 982 2 2:2 2 2D  @  D     F" " "P 7()dCC  DC @ 7()dCC    DC  F    
      F 7()dCC# # DC #L    
   D )9tDD+ + ED + + +s   5 AA;:A;