|
1 | 1 | import random |
| 2 | +from collections import Counter |
2 | 3 | from unittest import mock |
3 | 4 |
|
4 | 5 | import pytest |
@@ -261,32 +262,33 @@ def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value( |
261 | 262 |
|
262 | 263 |
|
263 | 264 | @pytest.mark.parametrize( |
264 | | - "traces_sample_rate,sampled_output,reports_output", |
| 265 | + "traces_sample_rate,sampled_output,expected_record_lost_event_calls", |
265 | 266 | [ |
266 | 267 | (None, False, []), |
267 | | - (0.0, False, [("sample_rate", "transaction")]), |
| 268 | + ( |
| 269 | + 0.0, |
| 270 | + False, |
| 271 | + [("sample_rate", "transaction", None, 1), ("sample_rate", "span", None, 1)], |
| 272 | + ), |
268 | 273 | (1.0, True, []), |
269 | 274 | ], |
270 | 275 | ) |
271 | 276 | def test_records_lost_event_only_if_traces_sample_rate_enabled( |
272 | | - sentry_init, traces_sample_rate, sampled_output, reports_output, monkeypatch |
| 277 | + sentry_init, |
| 278 | + capture_record_lost_event_calls, |
| 279 | + traces_sample_rate, |
| 280 | + sampled_output, |
| 281 | + expected_record_lost_event_calls, |
273 | 282 | ): |
274 | | - reports = [] |
275 | | - |
276 | | - def record_lost_event(reason, data_category=None, item=None): |
277 | | - reports.append((reason, data_category)) |
278 | | - |
279 | 283 | sentry_init(traces_sample_rate=traces_sample_rate) |
280 | | - |
281 | | - monkeypatch.setattr( |
282 | | - sentry_sdk.get_client().transport, "record_lost_event", record_lost_event |
283 | | - ) |
| 284 | + record_lost_event_calls = capture_record_lost_event_calls() |
284 | 285 |
|
285 | 286 | transaction = start_transaction(name="dogpark") |
286 | 287 | assert transaction.sampled is sampled_output |
287 | 288 | transaction.finish() |
288 | 289 |
|
289 | | - assert reports == reports_output |
| 290 | + # Using Counter since order does not matter |
| 291 | + assert Counter(record_lost_event_calls) == Counter(expected_record_lost_event_calls) |
290 | 292 |
|
291 | 293 |
|
292 | 294 | @pytest.mark.parametrize( |
|
0 commit comments