@@ -157,43 +157,43 @@ def test_api_request_time_dynamic(mock_send, caplog, elasticapm_client):
157
157
assert mock_send .call_count == 0
158
158
159
159
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
+
161
166
@mock .patch ("elasticapm.transport.base.Transport._flush" )
162
167
def 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 " )
164
169
transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
165
170
transport .start_thread ()
166
171
try :
167
172
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 )))
171
174
transport ._flushed .wait (timeout = 0.1 )
175
+ _cleanup_flush_mock_buffers (mock_flush )
172
176
assert mock_flush .call_count == 1
173
177
elasticapm_client .config .update (version = "1" , api_request_size = "1mb" )
174
178
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 )))
178
180
transport ._flushed .wait (timeout = 0.1 )
179
181
# Should be unchanged because our buffer limit is much higher.
180
182
assert mock_flush .call_count == 1
181
183
finally :
182
184
transport .close ()
183
185
184
186
185
- @pytest .mark .skipif (sys .version_info >= (3 , 12 ), reason = "Failing locally on 3.12.0rc1" ) # TODO py3.12
186
187
@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 )
188
189
def test_flush_time_size (mock_flush , caplog , elasticapm_client ):
189
190
transport = Transport (client = elasticapm_client , queue_chill_count = 1 )
190
191
transport .start_thread ()
191
192
try :
192
193
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 )))
196
195
transport ._flushed .wait (timeout = 0.1 )
196
+ _cleanup_flush_mock_buffers (mock_flush )
197
197
assert mock_flush .call_count == 1
198
198
finally :
199
199
transport .close ()
0 commit comments