@@ -620,6 +620,71 @@ async def test_conflict_does_not_hide_missing_collection(definition):
620620 assert result .value is missing
621621
622622
623+ @pytest .mark .parametrize ("matching_schema" , [True , False ])
624+ @pytest .mark .parametrize ("transport" , ["rest" , "grpc" ])
625+ async def test_create_conflict_waits_for_readable_schema (collection_factory , client , matching_schema , transport ):
626+ collection = collection_factory ()
627+ await collection .ensure_collection_exists ()
628+ info = await client .get_collection (collection .collection_name )
629+ if not matching_schema :
630+ info .config .params .vectors ["dense_text" ].size = 4
631+ if transport == "grpc" :
632+ conflict = AioRpcError (StatusCode .ALREADY_EXISTS , Metadata (), Metadata (), "collection already exists" )
633+ not_ready = AioRpcError (
634+ StatusCode .INTERNAL , Metadata (), Metadata (), "Service internal error: 0 of 0 read operations failed"
635+ )
636+ else :
637+ conflict = UnexpectedResponse (409 , "Conflict" , b"exists" , Headers ())
638+ not_ready = UnexpectedResponse (
639+ 500 ,
640+ "Internal Server Error" ,
641+ b'{"status":{"error":"Service internal error: 0 of 0 read operations failed"}}' ,
642+ Headers (),
643+ )
644+ with (
645+ patch .object (client , "collection_exists" , return_value = False ),
646+ patch .object (client , "create_collection" , side_effect = conflict ),
647+ patch .object (client , "get_collection" , side_effect = [not_ready , not_ready , info ]) as get_collection ,
648+ ):
649+ if matching_schema :
650+ await collection .ensure_collection_exists ()
651+ else :
652+ with pytest .raises (ValueError , match = "does not match" ):
653+ await collection .ensure_collection_exists ()
654+ assert get_collection .await_count == 3
655+
656+
657+ @pytest .mark .parametrize (
658+ ("conflict" , "error" , "expected_reads" ),
659+ [
660+ (True , UnexpectedResponse (500 , "Internal Server Error" , b"0 of 0 read operations failed" , Headers ()), 6 ),
661+ (False , UnexpectedResponse (500 , "Internal Server Error" , b"0 of 0 read operations failed" , Headers ()), 1 ),
662+ (True , UnexpectedResponse (500 , "Internal Server Error" , b"unrelated server failure" , Headers ()), 1 ),
663+ (True , UnexpectedResponse (403 , "Forbidden" , b"not authorized" , Headers ()), 1 ),
664+ (True , AioRpcError (StatusCode .INTERNAL , Metadata (), Metadata (), "0 of 0 read operations failed" ), 6 ),
665+ (False , AioRpcError (StatusCode .INTERNAL , Metadata (), Metadata (), "0 of 0 read operations failed" ), 1 ),
666+ (True , AioRpcError (StatusCode .INTERNAL , Metadata (), Metadata (), "unrelated server failure" ), 1 ),
667+ (True , AioRpcError (StatusCode .INTERNAL , Metadata (), Metadata (), None ), 1 ),
668+ (True , AioRpcError (StatusCode .PERMISSION_DENIED , Metadata (), Metadata (), "not authorized" ), 1 ),
669+ ],
670+ )
671+ async def test_collection_read_retries_are_bounded_and_specific (definition , conflict , error , expected_reads ):
672+ client = AsyncMock (spec = AsyncQdrantClient )
673+ client .collection_exists .return_value = not conflict
674+ client .create_collection .side_effect = (
675+ AioRpcError (StatusCode .ALREADY_EXISTS , Metadata (), Metadata (), "collection already exists" )
676+ if isinstance (error , AioRpcError )
677+ else UnexpectedResponse (409 , "Conflict" , b"exists" , Headers ())
678+ )
679+ client .get_collection .side_effect = error
680+ collection = QdrantCollection (dict , definition = definition , collection_name = "test" , async_client = client )
681+ with pytest .raises (type (error )) as result :
682+ await collection .ensure_collection_exists ()
683+ assert result .value is error
684+ assert client .get_collection .await_count == expected_reads
685+ assert client .create_collection .await_count == int (conflict )
686+
687+
623688@pytest .mark .parametrize ("configuration" , ["uint8" , "flat" ])
624689async def test_existing_vector_datatype_and_index_mismatch (collection_factory , client , configuration ):
625690 definition = VectorStoreCollectionDefinition ([
0 commit comments