Skip to content

Commit

Permalink
(wip): Fix test_records_lost_event_only...
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeasaurusrex committed Jul 9, 2024
1 parent fb4822a commit 07d9da7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
from collections import Counter
from unittest import mock

import pytest
Expand Down Expand Up @@ -261,32 +262,33 @@ def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value(


@pytest.mark.parametrize(
"traces_sample_rate,sampled_output,reports_output",
"traces_sample_rate,sampled_output,expected_record_lost_event_calls",
[
(None, False, []),
(0.0, False, [("sample_rate", "transaction")]),
(
0.0,
False,
[("sample_rate", "transaction", None, 1), ("sample_rate", "span", None, 1)],
),
(1.0, True, []),
],
)
def test_records_lost_event_only_if_traces_sample_rate_enabled(
sentry_init, traces_sample_rate, sampled_output, reports_output, monkeypatch
sentry_init,
capture_record_lost_event_calls,
traces_sample_rate,
sampled_output,
expected_record_lost_event_calls,
):
reports = []

def record_lost_event(reason, data_category=None, item=None):
reports.append((reason, data_category))

sentry_init(traces_sample_rate=traces_sample_rate)

monkeypatch.setattr(
sentry_sdk.get_client().transport, "record_lost_event", record_lost_event
)
record_lost_event_calls = capture_record_lost_event_calls()

transaction = start_transaction(name="dogpark")
assert transaction.sampled is sampled_output
transaction.finish()

assert reports == reports_output
# Using Counter since order does not matter
assert Counter(record_lost_event_calls) == Counter(expected_record_lost_event_calls)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 07d9da7

Please sign in to comment.