@@ -164,43 +164,43 @@ def test_api_request_time_dynamic(mock_send, caplog, elasticapm_client):
164
164
assert mock_send .call_count == 0
165
165
166
166
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
+ buffer .close ()
171
+
172
+
168
173
@mock .patch ("elasticapm.transport.base.Transport._flush" )
169
174
def test_api_request_size_dynamic (mock_flush , caplog , elasticapm_client ):
170
- elasticapm_client .config .update (version = "1" , api_request_size = "100b " )
175
+ elasticapm_client .config .update (version = "1" , api_request_size = "9b " )
171
176
transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
172
177
transport .start_thread ()
173
178
try :
174
179
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 )))
180
+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
178
181
transport ._flushed .wait (timeout = 0.1 )
182
+ _cleanup_flush_mock_buffers (mock_flush )
179
183
assert mock_flush .call_count == 1
180
184
elasticapm_client .config .update (version = "1" , api_request_size = "1mb" )
181
185
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 )))
186
+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
185
187
transport ._flushed .wait (timeout = 0.1 )
186
188
# Should be unchanged because our buffer limit is much higher.
187
189
assert mock_flush .call_count == 1
188
190
finally :
189
191
transport .close ()
190
192
191
193
192
- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
193
194
@mock .patch ("elasticapm.transport.base.Transport._flush" )
194
- @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "100b " }], indirect = True )
195
+ @pytest .mark .parametrize ("elasticapm_client" , [{"api_request_size" : "9b " }], indirect = True )
195
196
def test_flush_time_size (mock_flush , caplog , elasticapm_client ):
196
197
transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
197
198
transport .start_thread ()
198
199
try :
199
200
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 )))
201
+ transport .queue ("error" , "" .join (random .choice (string .ascii_letters ) for i in range (2000 )))
203
202
transport ._flushed .wait (timeout = 0.1 )
203
+ _cleanup_flush_mock_buffers (mock_flush )
204
204
assert mock_flush .call_count == 1
205
205
finally :
206
206
transport .close ()
0 commit comments