Skip to content

Commit

Permalink
fix frame counts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Feb 1, 2025
1 parent 467fa8b commit d5a7c4a
Showing 1 changed file with 170 additions and 80 deletions.
250 changes: 170 additions & 80 deletions tests/sentry/grouping/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,35 @@ def test_stacktrace_component_tallies_frame_types_simple(self):
# `normalize_stacktraces=True` forces the custom stacktrace enhancements to run
variants = self.event.get_grouping_variants(normalize_stacktraces=True)

for variant_name in ["app", "system"]:
exception_component = variants[variant_name].component.values[0]
assert isinstance(exception_component, ExceptionGroupingComponent)
stacktrace_component = find_given_child_component(
exception_component, StacktraceGroupingComponent
)
assert stacktrace_component
system_exception_component = variants["system"].component.values[0]
assert isinstance(system_exception_component, ExceptionGroupingComponent)
system_stacktrace_component = find_given_child_component(
system_exception_component, StacktraceGroupingComponent
)
assert system_stacktrace_component

assert stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=11,
system_contributing_frames=21,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
)
assert system_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=11,
system_contributing_frames=21,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
)

# In the app variant, there's no such thing as a contributing system frame, so all the
# system frames count as non-contributing
app_exception_component = variants["app"].component.values[0]
assert isinstance(app_exception_component, ExceptionGroupingComponent)
app_stacktrace_component = find_given_child_component(
app_exception_component, StacktraceGroupingComponent
)
assert app_stacktrace_component

assert app_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=32,
system_contributing_frames=0,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
)

def test_stacktrace_component_tallies_frame_types_not_all_types_present(self):
self.event.data["exception"]["values"][0]["stacktrace"] = {
Expand All @@ -142,20 +157,35 @@ def test_stacktrace_component_tallies_frame_types_not_all_types_present(self):
# `normalize_stacktraces=True` forces the custom stacktrace enhancements to run
variants = self.event.get_grouping_variants(normalize_stacktraces=True)

for variant_name in ["app", "system"]:
exception_component = variants[variant_name].component.values[0]
assert isinstance(exception_component, ExceptionGroupingComponent)
stacktrace_component = find_given_child_component(
exception_component, StacktraceGroupingComponent
)
assert stacktrace_component
system_exception_component = variants["system"].component.values[0]
assert isinstance(system_exception_component, ExceptionGroupingComponent)
system_stacktrace_component = find_given_child_component(
system_exception_component, StacktraceGroupingComponent
)
assert system_stacktrace_component

assert stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=0,
system_contributing_frames=20,
in_app_non_contributing_frames=0,
in_app_contributing_frames=13,
)
assert system_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=0,
system_contributing_frames=20,
in_app_non_contributing_frames=0,
in_app_contributing_frames=13,
)

# In the app variant, there's no such thing as a contributing system frame, so all the
# system frames count as non-contributing
app_exception_component = variants["app"].component.values[0]
assert isinstance(app_exception_component, ExceptionGroupingComponent)
app_stacktrace_component = find_given_child_component(
app_exception_component, StacktraceGroupingComponent
)
assert app_stacktrace_component

assert app_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=20,
system_contributing_frames=0,
in_app_non_contributing_frames=0,
in_app_contributing_frames=13,
)

def test_exception_component_uses_stacktrace_frame_counts(self):
self.event.data["exception"]["values"][0]["stacktrace"] = {
Expand All @@ -170,21 +200,37 @@ def test_exception_component_uses_stacktrace_frame_counts(self):
# `normalize_stacktraces=True` forces the custom stacktrace enhancements to run
variants = self.event.get_grouping_variants(normalize_stacktraces=True)

for variant_name in ["app", "system"]:
exception_component = variants[variant_name].component.values[0]
assert isinstance(exception_component, ExceptionGroupingComponent)
stacktrace_component = find_given_child_component(
exception_component, StacktraceGroupingComponent
)
assert stacktrace_component
system_exception_component = variants["system"].component.values[0]
assert isinstance(system_exception_component, ExceptionGroupingComponent)
system_stacktrace_component = find_given_child_component(
system_exception_component, StacktraceGroupingComponent
)
assert system_stacktrace_component

assert stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=4,
system_contributing_frames=15,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
)
assert exception_component.frame_counts == stacktrace_component.frame_counts
assert system_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=4,
system_contributing_frames=15,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
)
assert system_exception_component.frame_counts == system_stacktrace_component.frame_counts

# In the app variant, there's no such thing as a contributing system frame, so all the
# system frames count as non-contributing
app_exception_component = variants["app"].component.values[0]
assert isinstance(app_exception_component, ExceptionGroupingComponent)
app_stacktrace_component = find_given_child_component(
app_exception_component, StacktraceGroupingComponent
)
assert app_stacktrace_component

assert app_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=19,
system_contributing_frames=0,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
)
assert app_exception_component.frame_counts == app_stacktrace_component.frame_counts

def test_threads_component_uses_stacktrace_frame_counts(self):
self.event.data["threads"] = self.event.data.pop("exception")
Expand All @@ -200,21 +246,37 @@ def test_threads_component_uses_stacktrace_frame_counts(self):
# `normalize_stacktraces=True` forces the custom stacktrace enhancements to run
variants = self.event.get_grouping_variants(normalize_stacktraces=True)

for variant_name in ["app", "system"]:
threads_component = variants[variant_name].component.values[0]
assert isinstance(threads_component, ThreadsGroupingComponent)
stacktrace_component = find_given_child_component(
threads_component, StacktraceGroupingComponent
)
assert stacktrace_component
system_threads_component = variants["system"].component.values[0]
assert isinstance(system_threads_component, ThreadsGroupingComponent)
system_stacktrace_component = find_given_child_component(
system_threads_component, StacktraceGroupingComponent
)
assert system_stacktrace_component

assert stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=20,
system_contributing_frames=12,
in_app_non_contributing_frames=20,
in_app_contributing_frames=13,
)
assert threads_component.frame_counts == stacktrace_component.frame_counts
assert system_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=20,
system_contributing_frames=12,
in_app_non_contributing_frames=20,
in_app_contributing_frames=13,
)
assert system_threads_component.frame_counts == system_stacktrace_component.frame_counts

# In the app variant, there's no such thing as a contributing system frame, so all the
# system frames count as non-contributing
app_threads_component = variants["app"].component.values[0]
assert isinstance(app_threads_component, ThreadsGroupingComponent)
app_stacktrace_component = find_given_child_component(
app_threads_component, StacktraceGroupingComponent
)
assert app_stacktrace_component

assert app_stacktrace_component.frame_counts == Counter(
system_non_contributing_frames=32,
system_contributing_frames=0,
in_app_non_contributing_frames=20,
in_app_contributing_frames=13,
)
assert app_threads_component.frame_counts == app_stacktrace_component.frame_counts

def test_chained_exception_component_sums_stacktrace_frame_counts(self):
self.event.data["exception"]["values"] = [
Expand All @@ -241,30 +303,58 @@ def test_chained_exception_component_sums_stacktrace_frame_counts(self):
# `normalize_stacktraces=True` forces the custom stacktrace enhancements to run
variants = self.event.get_grouping_variants(normalize_stacktraces=True)

for variant_name in ["app", "system"]:
chained_exception_component = variants[variant_name].component.values[0]
assert isinstance(chained_exception_component, ChainedExceptionGroupingComponent)
exception_components = chained_exception_component.values
assert [
exception_component.frame_counts for exception_component in exception_components
] == [
Counter(
system_non_contributing_frames=11,
system_contributing_frames=21,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
),
Counter(
system_non_contributing_frames=4,
system_contributing_frames=15,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
),
]
system_chained_exception_component = variants["system"].component.values[0]
assert isinstance(system_chained_exception_component, ChainedExceptionGroupingComponent)
system_exception_components = system_chained_exception_component.values
assert [
exception_component.frame_counts for exception_component in system_exception_components
] == [
Counter(
system_non_contributing_frames=11,
system_contributing_frames=21,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
),
Counter(
system_non_contributing_frames=4,
system_contributing_frames=15,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
),
]

assert chained_exception_component.frame_counts == Counter(
system_non_contributing_frames=15,
system_contributing_frames=36,
in_app_non_contributing_frames=21,
in_app_contributing_frames=39,
)
assert system_chained_exception_component.frame_counts == Counter(
system_non_contributing_frames=15,
system_contributing_frames=36,
in_app_non_contributing_frames=21,
in_app_contributing_frames=39,
)

# In the app variant, there's no such thing as a contributing system frame, so all the
# system frames count as non-contributing
app_chained_exception_component = variants["app"].component.values[0]
assert isinstance(app_chained_exception_component, ChainedExceptionGroupingComponent)
app_exception_components = app_chained_exception_component.values
assert [
exception_component.frame_counts for exception_component in app_exception_components
] == [
Counter(
system_non_contributing_frames=32,
system_contributing_frames=0,
in_app_non_contributing_frames=12,
in_app_contributing_frames=31,
),
Counter(
system_non_contributing_frames=19,
system_contributing_frames=0,
in_app_non_contributing_frames=9,
in_app_contributing_frames=8,
),
]

assert app_chained_exception_component.frame_counts == Counter(
system_non_contributing_frames=51,
system_contributing_frames=0,
in_app_non_contributing_frames=21,
in_app_contributing_frames=39,
)

0 comments on commit d5a7c4a

Please sign in to comment.