o
    3Ih                     @   sj   d dl mZ d dlZd dlmZ d dlmZmZ deddfddZdeddfd	d
Z	deddfddZ
dS )    )ThreadPoolExecutorN)	ClientAPI)ChromaErrorUniqueConstraintErrorclientreturnc              
   C   s   | j dddddd z| j dddddd J d tyG } z!td| d|jd	 v s5t|ts<J W Y d }~d S W Y d }~d S d }~ww )
Ntest   )zhnsw:construction_efzhnsw:search_efzhnsw:M)namemetadataFExpected exceptionz2Collection creation failed as expected with error zalready existsr   )create_collection	Exceptionprintargs
isinstancer   r   e r   a/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/chromadb/test/api/test_collection.py test_duplicate_collection_create   s$   

8r   c              
   C   sX   z
| j dd J d ty+ } ztd| d|jd v s J W Y d }~d S d }~ww )Ntest101)r
   Fr   z2Collection deletion failed as expected with error does not existr   )delete_collectionr   r   r   r   r   r   r   #test_not_existing_collection_delete   s   
 r   c                    s   d}t t dtdd f fddt|d3fddt|D }|D ]}z|  W q( tyC } zJ d
| d }~ww W d    d S 1 sOw   Y  d S )N2   ir   c              
      s   z  }|jksJ W n ty( } zd| vr|W Y d }~nd }~ww z| d dkr8  W d S W d S  tyU } zd| vrJ|W Y d }~d S d }~ww )N
concurrent   r   r   )get_or_create_collectionr
   r   messager   )r   collr   )r   new_namer   r   create_maybe_delete_collection/   s&   
zHtest_multithreaded_get_or_create.<locals>.create_maybe_delete_collection)max_workersc                    s   g | ]}  |qS r   )submit).0r   )r#   executorr   r   
<listcomp>@   s    z4test_multithreaded_get_or_create.<locals>.<listcomp>FzThread raised an exception: )struuiduuid4intr   rangeresultr   )r   	N_THREADSfuturesfuturer   r   )r   r#   r'   r"   r    test_multithreaded_get_or_create+   s    "r2   )concurrent.futuresr   r*   chromadb.apir   chromadb.errorsr   r   r   r   r2   r   r   r   r   <module>   s    

