66from docarray import DocList
77from docarray .documents import TextDoc
88from docarray .store .file import ConcurrentPushException , FileDocStore
9- from docarray .utils ._internal .cache import _get_cache_path
109from docarray .utils ._internal .pydantic import is_pydantic_v2
10+ from docarray .utils ._internal .cache import _get_cache_path
1111from tests .integrations .store import gen_text_docs , get_test_da , profile_memory
1212
1313DA_LEN : int = 2 ** 10
14- TOLERANCE_RATIO = 0.1 # Percentage of difference allowed in stream vs non-stream test
14+ TOLERANCE_RATIO = 0.1 # Percentage of difference allowed when streaming between a long and a shorter DA
1515
1616
1717def test_path_resolution ():
@@ -23,7 +23,6 @@ def test_path_resolution():
2323
2424
2525def test_pushpull_correct (capsys , tmp_path : Path ):
26- tmp_path .mkdir (parents = True , exist_ok = True )
2726 namespace_dir = tmp_path
2827 da1 = get_test_da (DA_LEN )
2928
@@ -51,7 +50,6 @@ def test_pushpull_correct(capsys, tmp_path: Path):
5150
5251
5352def test_pushpull_stream_correct (capsys , tmp_path : Path ):
54- tmp_path .mkdir (parents = True , exist_ok = True )
5553 namespace_dir = tmp_path
5654 da1 = get_test_da (DA_LEN )
5755
@@ -85,10 +83,8 @@ def test_pushpull_stream_correct(capsys, tmp_path: Path):
8583
8684
8785# for some reason this test is failing with pydantic v2
88- @pytest .mark .skipif (is_pydantic_v2 , reason = "Not working with pydantic v2 for now" )
8986@pytest .mark .slow
9087def test_pull_stream_vs_pull_full (tmp_path : Path ):
91- tmp_path .mkdir (parents = True , exist_ok = True )
9288 namespace_dir = tmp_path
9389 DocList [TextDoc ].push_stream (
9490 gen_text_docs (DA_LEN * 1 ),
@@ -136,15 +132,23 @@ def get_total_full(url: str):
136132 ), 'Streamed and non-streamed pull should have similar statistics'
137133
138134 assert (
139- abs ( long_stream_peak - short_stream_peak ) / short_stream_peak < TOLERANCE_RATIO
140- ), 'Streamed memory usage should not be dependent on the size of the data '
135+ long_full_peak > long_stream_peak
136+ ), 'Peak of memory using full should be larger than when streaming '
141137 assert (
142- abs (long_full_peak - short_full_peak ) / short_full_peak > TOLERANCE_RATIO
143- ), 'Full pull memory usage should be dependent on the size of the data'
138+ short_full_peak > short_stream_peak
139+ ), 'Peak of memory using full should be larger than when streaming'
140+ if not is_pydantic_v2 :
141+ # I bet there is some memory that Pydantic is leaking
142+ assert (
143+ abs (long_stream_peak - short_stream_peak ) / short_stream_peak
144+ < TOLERANCE_RATIO
145+ ), 'Streamed memory usage should not be dependent on the size of the data'
146+ assert (
147+ abs (long_full_peak - short_full_peak ) / short_full_peak > TOLERANCE_RATIO
148+ ), 'Full pull memory usage should be dependent on the size of the data'
144149
145150
146151def test_list_and_delete (tmp_path : Path ):
147- tmp_path .mkdir (parents = True , exist_ok = True )
148152 namespace_dir = str (tmp_path )
149153
150154 da_names = FileDocStore .list (namespace_dir , show_table = False )
@@ -179,7 +183,6 @@ def test_list_and_delete(tmp_path: Path):
179183
180184def test_concurrent_push_pull (tmp_path : Path ):
181185 # Push to DA that is being pulled should not mess up the pull
182- tmp_path .mkdir (parents = True , exist_ok = True )
183186 namespace_dir = tmp_path
184187
185188 DocList [TextDoc ].push_stream (
@@ -214,7 +217,6 @@ def test_concurrent_push(tmp_path: Path):
214217 # Double push should fail the second push
215218 import time
216219
217- tmp_path .mkdir (parents = True , exist_ok = True )
218220 namespace_dir = tmp_path
219221
220222 DocList [TextDoc ].push_stream (
0 commit comments