@@ -281,6 +281,85 @@ def metadata_capture_collection(
281281 return weaviate_client .collections .use ("MetadataCaptureCollection" ), service
282282
283283
284+ BATCH_INSERT_TIMEOUT = 5
285+
286+
287+ class MockBatchDeadlineCaptureWeaviateService (weaviate_pb2_grpc .WeaviateServicer ):
288+ captured_time_remaining : float = - 1.0
289+
290+ def BatchObjects (
291+ self , request : batch_pb2 .BatchObjectsRequest , context : grpc .ServicerContext
292+ ) -> batch_pb2 .BatchObjectsReply :
293+ self .captured_time_remaining = context .time_remaining ()
294+ return batch_pb2 .BatchObjectsReply ()
295+
296+
297+ @pytest .fixture (scope = "function" )
298+ def weaviate_batch_insert_timeout_client (
299+ weaviate_mock : HTTPServer , start_grpc_server : grpc .Server
300+ ) -> Generator [weaviate .WeaviateClient , None , None ]:
301+ weaviate_mock .expect_request (f"/v1/schema/{ mock_class ['class' ]} " ).respond_with_json (mock_class )
302+ client = weaviate .connect_to_local (
303+ host = MOCK_IP ,
304+ port = MOCK_PORT ,
305+ grpc_port = MOCK_PORT_GRPC ,
306+ additional_config = weaviate .classes .init .AdditionalConfig (
307+ timeout = weaviate .classes .init .Timeout (insert = BATCH_INSERT_TIMEOUT )
308+ ),
309+ )
310+ yield client
311+ client .close ()
312+
313+
314+ @pytest .fixture (scope = "function" )
315+ def batch_deadline_capture_collection (
316+ weaviate_batch_insert_timeout_client : weaviate .WeaviateClient ,
317+ start_grpc_server : grpc .Server ,
318+ ) -> tuple [weaviate .collections .Collection , MockBatchDeadlineCaptureWeaviateService ]:
319+ service = MockBatchDeadlineCaptureWeaviateService ()
320+ weaviate_pb2_grpc .add_WeaviateServicer_to_server (service , start_grpc_server )
321+ return (
322+ weaviate_batch_insert_timeout_client .collections .use (mock_class ["class" ]),
323+ service ,
324+ )
325+
326+
327+ BATCH_INSERT_TIMEOUT_SHORT = 0.5
328+
329+
330+ @pytest .fixture (scope = "function" )
331+ def weaviate_batch_insert_timeout_short_client (
332+ weaviate_mock : HTTPServer , start_grpc_server : grpc .Server
333+ ) -> Generator [weaviate .WeaviateClient , None , None ]:
334+ weaviate_mock .expect_request (f"/v1/schema/{ mock_class ['class' ]} " ).respond_with_json (mock_class )
335+ client = weaviate .connect_to_local (
336+ host = MOCK_IP ,
337+ port = MOCK_PORT ,
338+ grpc_port = MOCK_PORT_GRPC ,
339+ additional_config = weaviate .classes .init .AdditionalConfig (
340+ timeout = weaviate .classes .init .Timeout (insert = BATCH_INSERT_TIMEOUT_SHORT )
341+ ),
342+ )
343+ yield client
344+ client .close ()
345+
346+
347+ @pytest .fixture (scope = "function" )
348+ def batch_slow_response_collection (
349+ weaviate_batch_insert_timeout_short_client : weaviate .WeaviateClient ,
350+ start_grpc_server : grpc .Server ,
351+ ) -> weaviate .collections .Collection :
352+ class MockWeaviateService (weaviate_pb2_grpc .WeaviateServicer ):
353+ def BatchObjects (
354+ self , request : batch_pb2 .BatchObjectsRequest , context : grpc .ServicerContext
355+ ) -> batch_pb2 .BatchObjectsReply :
356+ time .sleep (BATCH_INSERT_TIMEOUT_SHORT + 1 )
357+ return batch_pb2 .BatchObjectsReply ()
358+
359+ weaviate_pb2_grpc .add_WeaviateServicer_to_server (MockWeaviateService (), start_grpc_server )
360+ return weaviate_batch_insert_timeout_short_client .collections .use (mock_class ["class" ])
361+
362+
284363class MockRetriesWeaviateService (weaviate_pb2_grpc .WeaviateServicer ):
285364 search_count = 0
286365 tenants_count = 0
0 commit comments