
    ug$              
       B   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	Z	d dl
Z
d dlmZ d dlmZmZ d dlmZmZmZ d d	lmZ d d
lmZmZ  G d de      Zdededededdf
dZ G d d      ZdZ e
j<                         deeeef   ddf   fd       Zdeeef   ddfdZ y)    )futures)Queue)Thread)	GeneratorTupleN)to_proto_submit)PushLogsRequestPushLogsResponse)LogServiceServicerLogServiceStub add_LogServiceServicer_to_server) RetryOnRpcErrorClientInterceptor)	OperationOperationRecordc                   j     e Zd ZU eed<   eed<   dededdf fdZdedej                  de
fdZ xZS )	FlakyLogServiceServicernum_requests_to_failreceived_requestsreturnNc                 >    t         |           || _        || _        y N)super__init__r   r   )selfr   r   	__class__s      S/var/www/openai/venv/lib/python3.12/site-packages/chromadb/test/proto/test_utils.pyr   z FlakyLogServiceServicer.__init__   s    $8!!2    requestcontextc                 b   | j                   dkD  rw| xj                   dz  c_         |j                  t        j                  j                         |j                  d       | j                  j                  d|d       t               S | j                  j                  d|d       t        d      S )Nr      zService unavailablefailed)statusr   success)record_count)	r   set_codegrpc
StatusCodeUNAVAILABLEset_detailsr   putr
   )r   r   r   s      r   PushLogsz FlakyLogServiceServicer.PushLogs   s     $$q(%%*%T__889 56""&&(w'OP#%%""iG#LMQ//r   )__name__
__module____qualname__int__annotations__r   r   r	   r'   ServicerContextr
   r,   __classcell__)r   s   @r   r   r      sL    3S 3U 3t 3
0&0151E1E0	0r   r   r   r   started_queue
stop_queuer   c                 (   t        j                  t        j                  d            }t	        t        | |      |       |j                  d       |j                          |j                  d       |j                          |j                  d       y )Nr!   )max_workersz
[::]:50051r   )r'   serverr   ThreadPoolExecutorr   r   add_insecure_portstartr+   getstop)r   r   r4   r5   r8   s        r   start_serverr>   +   so     [[33BCF$ 46GH& \*
LLNaNN
KKNr   c                   <    e Zd ZU eed<   deddfdZdededdfdZy)	LogServiceRetryClientstubgrpc_urlr   Nc                     t        j                  |      }t               g}t        j                  |g| }t	        |      | _        y r   )r'   insecure_channelr   intercept_channelr   rA   )r   rB   channelinterceptorss       r   r   zLogServiceRetryClient.__init__@   s>    ''18:;((@<@"7+	r   collection_idrecordc                 l    t        |      }t        ||g      }| j                  j                  |       y )N)rH   records)r   r	   rA   r,   )r   rH   rI   proto_recordr   s        r   push_logzLogServiceRetryClient.push_logF   s,    &v.!~V		7#r   )	r-   r.   r/   r   r1   strr   r   rM    r   r   r@   r@   =   s5    
, , ,$c $? $t $r   r@      c               #     K   t               } t               }t               }t        t        t        | ||f      }|j	                          |j                          t        d      }|| f |j                  d       |j                          y w)N)targetargslocalhost:50051r!   )	r   r   r>   NUM_REQUESTS_TO_FAILr;   r<   r@   r+   join)r   r4   r5   server_threadclients        r   -client_for_flaky_server_and_received_requestsrY   O   s       %w 7MJ"$5}jQM "#45F
#
##NN1s   BBrY   c           
         | \  }}t        d      }|j                  dt        dd d d t        j                               g }|j                         s0|j                  |j                                |j                         s0t        |      t        dz   k(  sJ t        d |d t         D              sJ |t           d   dk(  sJ y )	NrT   test1)id	embeddingencodingmetadata	operationr!   c              3   ,   K   | ]  }|d    dk(    yw)r#   r"   NrO   ).0rs     r   	<genexpr>z)test_retry_interceptor.<locals>.<genexpr>}   s     P0O1q{h&0Os   r#   r$   )r@   rM   r   r   ADDemptyappendr<   lenrU   all)rY   rX   r   requestss       r   test_retry_interceptorrl   g   s     #PV"#45F
OOmm	
	 H%%')--/0  %%' x=014444P9N:N0OPPPP()(3y@@@r   )!
concurrentr   queuer   	threadingr   typingr   r   r'   pytestchromadb.proto.convertr   chromadb.proto.logservice_pb2r	   r
   "chromadb.proto.logservice_pb2_grpcr   r   r   chromadb.proto.utilsr   chromadb.typesr   r   r   r0   r>   r@   rU   fixturerY   rl   rO   r   r   <module>rx      s       #   2 K 
 B 500 00  	
 
$$ $   e)5014=> .A389NPU9U3VA	Ar   