@@ -157,43 +157,43 @@ def test_api_request_time_dynamic(mock_send, caplog, elasticapm_client):
157157 assert mock_send .call_count == 0
158158
159159
160- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
160+ def _cleanup_flush_mock_buffers (mock_flush ):
161+ args , kwargs = mock_flush .call_args
162+ buffer = args [0 ]
163+ buffer .close ()
164+
165+
161166@mock .patch ("elasticapm.transport.base.Transport._flush" )
162167def test_api_request_size_dynamic (mock_flush , caplog , elasticapm_client ):
163- elasticapm_client .config .update (version = "1" , api_request_size = "100b " )
168+ elasticapm_client .config .update (version = "1" , api_request_size = "9b " )
164169 transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
165170 transport .start_thread ()
166171 try :
167172 with caplog .at_level ("DEBUG" , "elasticapm.transport" ):
168- # we need to add lots of uncompressible data to fill up the gzip-internal buffer
169- for i in range (12 ):
170- transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
173+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
171174 transport ._flushed .wait (timeout = 0.1 )
175+ _cleanup_flush_mock_buffers (mock_flush )
172176 assert mock_flush .call_count == 1
173177 elasticapm_client .config .update (version = "1" , api_request_size = "1mb" )
174178 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 )))
179+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
178180 transport ._flushed .wait (timeout = 0.1 )
179181 # Should be unchanged because our buffer limit is much higher.
180182 assert mock_flush .call_count == 1
181183 finally :
182184 transport .close ()
183185
184186
185- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
186187@mock .patch ("elasticapm.transport.base.Transport._flush" )
187- @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "100b " }], indirect = True )
188+ @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "9b " }], indirect = True )
188189def test_flush_time_size (mock_flush , caplog , elasticapm_client ):
189190 transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
190191 transport .start_thread ()
191192 try :
192193 with caplog .at_level ("DEBUG" , "elasticapm.transport" ):
193- # we need to add lots of uncompressible data to fill up the gzip-internal buffer
194- for i in range (12 ):
195- transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
194+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
196195 transport ._flushed .wait (timeout = 0.1 )
196+ _cleanup_flush_mock_buffers (mock_flush )
197197 assert mock_flush .call_count == 1
198198 finally :
199199 transport .close ()
0 commit comments