@@ -164,43 +164,46 @@ def test_api_request_time_dynamic(mock_send, caplog, elasticapm_client):
164164 assert mock_send .call_count == 0
165165
166166
167- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
167+ def _cleanup_flush_mock_buffers (mock_flush ):
168+ args , kwargs = mock_flush .call_args
169+ buffer = args [0 ]
170+ fileobj = buffer .fileobj
171+ buffer .close ()
172+ compressed_data = fileobj .getbuffer ()
173+ compressed_data .release ()
174+
175+
168176@mock .patch ("elasticapm.transport.base.Transport._flush" )
169177def test_api_request_size_dynamic (mock_flush , caplog , elasticapm_client ):
170- elasticapm_client .config .update (version = "1" , api_request_size = "100b " )
178+ elasticapm_client .config .update (version = "1" , api_request_size = "9b " )
171179 transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
172180 transport .start_thread ()
173181 try :
174182 with caplog .at_level ("DEBUG" , "elasticapm.transport" ):
175- # we need to add lots of uncompressible data to fill up the gzip-internal buffer
176- for i in range (12 ):
177- transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
183+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
178184 transport ._flushed .wait (timeout = 0.1 )
179185 assert mock_flush .call_count == 1
186+ _cleanup_flush_mock_buffers (mock_flush )
180187 elasticapm_client .config .update (version = "1" , api_request_size = "1mb" )
181188 with caplog .at_level ("DEBUG" , "elasticapm.transport" ):
182- # we need to add lots of uncompressible data to fill up the gzip-internal buffer
183- for i in range (12 ):
184- transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
189+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
185190 transport ._flushed .wait (timeout = 0.1 )
186191 # Should be unchanged because our buffer limit is much higher.
187192 assert mock_flush .call_count == 1
188193 finally :
189194 transport .close ()
190195
191196
192- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
193197@mock .patch ("elasticapm.transport.base.Transport._flush" )
194- @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "100b " }], indirect = True )
198+ @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "9b " }], indirect = True )
195199def test_flush_time_size (mock_flush , caplog , elasticapm_client ):
196200 transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
197201 transport .start_thread ()
198202 try :
199203 with caplog .at_level ("DEBUG" , "elasticapm.transport" ):
200- # we need to add lots of uncompressible data to fill up the gzip-internal buffer
201- for i in range (12 ):
202- transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
204+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
203205 transport ._flushed .wait (timeout = 0.1 )
206+ _cleanup_flush_mock_buffers (mock_flush )
204207 assert mock_flush .call_count == 1
205208 finally :
206209 transport .close ()
0 commit comments