@@ -108,15 +108,17 @@ def test_get_all_many(self) -> None:
108108 "12.5 MB" , current_thread_only = True
109109 ) # assert that we're not doubling memory usagelimit_mem
110110 def test_memory_usage (
111- self , get_func : typing .Callable [[BytesQueueBuffer ], str ]
111+ self , get_func : typing .Callable [[BytesQueueBuffer ], bytes ]
112112 ) -> None :
113113 # Allocate 10 1MiB chunks
114114 buffer = BytesQueueBuffer ()
115115 for i in range (10 ):
116116 # This allocates 2MiB, putting the max at around 12MiB. Not sure why.
117117 buffer .put (bytes (2 ** 20 ))
118118
119- assert len (get_func (buffer )) == 10 * 2 ** 20
119+ result = get_func (buffer )
120+ assert type (result ) is bytes
121+ assert len (result ) == 10 * 2 ** 20
120122
121123 @pytest .mark .limit_memory ("10.01 MB" , current_thread_only = True )
122124 def test_get_all_memory_usage_single_chunk (self ) -> None :
@@ -125,6 +127,28 @@ def test_get_all_memory_usage_single_chunk(self) -> None:
125127 buffer .put (chunk )
126128 assert buffer .get_all () is chunk
127129
130+ @pytest .mark .parametrize (
131+ "finish_with_get_all" ,
132+ (True , False ),
133+ ids = ("finish_with_get_all" , "finish_with_get" ),
134+ )
135+ @pytest .mark .limit_memory ("11.01 MB" , current_thread_only = True )
136+ def test_memory_usage_splitting_chunk (self , finish_with_get_all : bool ) -> None :
137+ # Allocate a single 10MiB chunk, then read it in two parts.
138+ # Verifies that splitting a chunk doesn't cause additional memory allocation.
139+ buffer = BytesQueueBuffer ()
140+ chunk = bytes (10 * 2 ** 20 ) # 10 MiB
141+ buffer .put (chunk )
142+ for i in range (10 ):
143+ if finish_with_get_all and i == 9 :
144+ result = buffer .get_all ()
145+ else :
146+ result = buffer .get (2 ** 20 )
147+ assert type (result ) is bytes
148+ assert len (result ) == 2 ** 20
149+ del result
150+ assert len (buffer ) == 0
151+
128152
129153# A known random (i.e, not-too-compressible) payload generated with:
130154# "".join(random.choice(string.printable) for i in range(512))
0 commit comments