Skip to content

Commit

Permalink
split variants test into current and legacy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Oct 17, 2024
1 parent 2fc4061 commit cee9d5e
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions tests/sentry/grouping/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from sentry.grouping.component import GroupingComponent
from sentry.grouping.strategies.configurations import CONFIGURATIONS
from sentry.grouping.variants import BaseVariant
from sentry.testutils.pytest.fixtures import InstaSnapshotter
from sentry.models.project import Project
from sentry.projectoptions.defaults import DEFAULT_GROUPING_CONFIG
from sentry.testutils.pytest.fixtures import InstaSnapshotter, django_db_all
from tests.sentry.grouping import GROUPING_INPUTS_DIR, GroupingInput, with_grouping_inputs


Expand Down Expand Up @@ -59,11 +61,20 @@ def _dump_component(component: GroupingComponent, indent: int) -> None:

@with_grouping_inputs("grouping_input", GROUPING_INPUTS_DIR)
@pytest.mark.parametrize(
"config_name", CONFIGURATIONS.keys(), ids=lambda config_name: config_name.replace("-", "_")
"config_name",
set(CONFIGURATIONS.keys()) - {DEFAULT_GROUPING_CONFIG},
ids=lambda config_name: config_name.replace("-", "_"),
)
def test_event_hash_variant(
def test_variants_with_legacy_configs(
config_name: str, grouping_input: GroupingInput, insta_snapshot: InstaSnapshotter
) -> None:
"""
Run the variant snapshot tests using an minimal (and much more performant) save process.
Because manually cherry-picking only certain parts of the save process to run makes us much more
likely to fall out of sync with reality, for safety we only do this when testing legacy,
inactive grouping configs.
"""
event = grouping_input.create_event(config_name, use_full_ingest_pipeline=False)

# This ensures we won't try to touch the DB when getting event variants
Expand All @@ -72,6 +83,40 @@ def test_event_hash_variant(
_assert_and_snapshot_results(event, config_name, grouping_input.filename, insta_snapshot)


@django_db_all
@with_grouping_inputs("grouping_input", GROUPING_INPUTS_DIR)
@pytest.mark.parametrize(
"config_name",
# Technically we don't need to parameterize this since there's only one option, but doing it
# this way makes snapshots from this test organize themselves neatly alongside snapshots from
# the test of the legacy configs above
{DEFAULT_GROUPING_CONFIG},
ids=lambda config_name: config_name.replace("-", "_"),
)
def test_variants_with_current_default_config(
config_name: str,
grouping_input: GroupingInput,
insta_snapshot: InstaSnapshotter,
default_project: Project,
):
"""
Run the variant snapshot tests using the full `EventManager.save` process.
This is the most realistic way to test, but it's also slow, because it requires the overhead of
set-up/tear-down/general interaction with our full postgres database. We therefore only do it
when testing the current grouping config, and rely on a much faster manual test (below) for
previous grouping configs.
"""

event = grouping_input.create_event(
config_name, use_full_ingest_pipeline=True, project=default_project
)

_assert_and_snapshot_results(
event, DEFAULT_GROUPING_CONFIG, grouping_input.filename, insta_snapshot
)


def _assert_and_snapshot_results(
event: Event, config_name: str, input_file: str, insta_snapshot: InstaSnapshotter
) -> None:
Expand All @@ -89,6 +134,8 @@ def _assert_and_snapshot_results(

insta_snapshot(
output,
# Manually set the snapshot path so that both of the tests above will file their snapshots
# in the same spot
reference_file=path.join(
path.dirname(__file__),
"snapshots",
Expand Down

0 comments on commit cee9d5e

Please sign in to comment.