Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Jul 2, 2024
1 parent 8afc75b commit 88e2647
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sentry.testutils.helpers.eventprocessing import save_new_event
from sentry.utils.types import NonNone

EXPECTED_STACKTRACE_STRING = 'ZeroDivisionError: division by zero\n File "python_onboarding.py", function divide_by_zero\n divide = 1/0'
EXPECTED_STACKTRACE_STRING = 'ZeroDivisionError: division by zero\n Module "__main__", file "python_onboarding.py", function divide_by_zero\n divide = 1/0'


class GroupSimilarIssuesEmbeddingsTest(APITestCase):
Expand Down Expand Up @@ -90,6 +90,13 @@ def create_exception(
"hint": None,
"values": [exception_value],
},
{
"id": "module",
"name": None,
"contributes": True,
"hint": None,
"values": [exception_value],
},
],
}

Expand Down
25 changes: 18 additions & 7 deletions tests/sentry/seer/similarity/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class GetStacktraceStringTest(TestCase):
EXPECTED_STACKTRACE_STRING = 'ZeroDivisionError: division by zero\n File "python_onboarding.py", function divide_by_zero\n divide = 1/0'
EXPECTED_STACKTRACE_STRING = 'ZeroDivisionError: division by zero\n Module "__main__", file "python_onboarding.py", function divide_by_zero\n divide = 1/0'
BASE_APP_DATA: dict[str, Any] = {
"app": {
"type": "component",
Expand Down Expand Up @@ -417,6 +417,13 @@ def create_frames(
"contributes": contributes,
"hint": None,
"values": [
{
"id": "module",
"name": None,
"contributes": contributes,
"hint": None,
"values": ["__main__"],
},
{
"id": "filename",
"name": None,
Expand Down Expand Up @@ -488,7 +495,11 @@ def test_no_stacktrace(self):
def test_chained(self):
stacktrace_str = get_stacktrace_string(self.CHAINED_APP_DATA)
expected_stacktrace_str = (
'Exception: Catch divide by zero error\n File "python_onboarding.py", function <module>\n divide_by_zero()\n File "python_onboarding.py", function divide_by_zero\n raise Exception("Catch divide by zero error")\n'
"Exception: Catch divide by zero error\n"
+ ' Module "__main__", file "python_onboarding.py", function <module>\n'
+ " divide_by_zero()\n"
+ ' Module "__main__", file "python_onboarding.py", function divide_by_zero\n'
+ ' raise Exception("Catch divide by zero error")\n'
+ self.EXPECTED_STACKTRACE_STRING
)
assert stacktrace_str == expected_stacktrace_str
Expand Down Expand Up @@ -527,12 +538,12 @@ def test_chained_too_many_frames(self):
expected = "".join(
["OuterException: no way"]
+ [
f'\n File "hello.py", function hello_there\n outer line {i}'
f'\n Module "__main__", file "hello.py", function hello_there\n outer line {i}'
for i in range(1, 31) #
]
+ ["\nMiddleException: un-uh"]
+ [
f'\n File "hello.py", function hello_there\n middle line {i}'
f'\n Module "__main__", file "hello.py", function hello_there\n middle line {i}'
for i in range(11, 31)
]
+ ["\nInnerException: nope"]
Expand Down Expand Up @@ -579,12 +590,12 @@ def test_chained_too_many_frames_all_minified_js(self):
expected = "".join(
["OuterException: no way"]
+ [
f'\n File "hello.py", function hello_there\n {{snip}}outer line {i}{{snip}}'
f'\n Module "__main__", file "hello.py", function hello_there\n {{snip}}outer line {i}{{snip}}'
for i in range(1, 16) #
]
+ ["\nMiddleException: un-uh"]
+ [
f'\n File "hello.py", function hello_there\n {{snip}}middle line {i}{{snip}}'
f'\n Module "__main__", file "hello.py", function hello_there\n {{snip}}middle line {i}{{snip}}'
for i in range(11, 16)
]
+ ["\nInnerException: nope"]
Expand Down Expand Up @@ -635,7 +646,7 @@ def test_chained_too_many_frames_minified_js_frame_limit(self):

def test_thread(self):
stacktrace_str = get_stacktrace_string(self.MOBILE_THREAD_DATA)
assert stacktrace_str == 'File "", function TestHandler'
assert stacktrace_str == 'Module "", file "", function TestHandler'

def test_system(self):
data_system = copy.deepcopy(self.BASE_APP_DATA)
Expand Down
25 changes: 13 additions & 12 deletions tests/sentry/tasks/test_backfill_seer_grouping_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
}
],
}
EXCEPTION_STACKTRACE_STRING = (
'ZeroDivisionError: division by zero\n File "python_onboarding.py", function divide_by_zero'
)
EXCEPTION_STACKTRACE_STRING = 'ZeroDivisionError: division by zero\n Module "__main__", file "python_onboarding.py", function divide_by_zero'


@django_db_all
Expand Down Expand Up @@ -187,7 +185,7 @@ def test_lookup_group_data_stacktrace_bulk_success(self, mock_metrics):
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(5)
]
assert nodestore_results["data"] == expected_group_data
Expand Down Expand Up @@ -216,7 +214,7 @@ def test_lookup_group_data_stacktrace_bulk_success_multithread(self, mock_metric
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(5)
]
assert nodestore_results["data"] == expected_group_data
Expand Down Expand Up @@ -286,7 +284,7 @@ def test_lookup_group_data_stacktrace_bulk_not_stacktrace_grouping(self):
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(2)
]
# assert bulk_event_ids == {event.event_id for event in events}
Expand Down Expand Up @@ -321,7 +319,7 @@ def test_lookup_group_data_stacktrace_bulk_no_stacktrace_exception(self):
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(2)
]
assert bulk_group_data_stacktraces["data"] == expected_group_data
Expand Down Expand Up @@ -349,7 +347,7 @@ def test_lookup_group_data_stacktrace_bulk_with_fallback_success(self):
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(5)
]
assert bulk_group_data_stacktraces["data"] == expected_group_data
Expand Down Expand Up @@ -387,7 +385,7 @@ def test_lookup_group_data_stacktrace_bulk_with_fallback_use_single_fallback(
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(5)
]
assert bulk_group_data_stacktraces["data"] == expected_group_data
Expand Down Expand Up @@ -422,7 +420,7 @@ def test_lookup_group_data_stacktrace_bulk_with_fallback_event_lookup_error(self
for event in events
]
expected_stacktraces = [
f'Error{i}: error with value\n File "function_{i}.py", function function_{i}'
f'Error{i}: error with value\n Module "__main__", file "function_{i}.py", function function_{i}'
for i in range(4)
]
assert bulk_group_data_stacktraces["data"] == expected_group_data
Expand Down Expand Up @@ -575,8 +573,11 @@ def test_backfill_seer_grouping_records_success_cohorts_setting_defined(
group_hashes = GroupHash.objects.all().distinct("group_id")
self.group_hashes = {group_hash.group_id: group_hash.hash for group_hash in group_hashes}

with TaskRunner(), override_settings(
SIMILARITY_BACKFILL_COHORT_MAP={"test": [self.project.id, project2.id]}
with (
TaskRunner(),
override_settings(
SIMILARITY_BACKFILL_COHORT_MAP={"test": [self.project.id, project2.id]}
),
):
backfill_seer_grouping_records_for_project(
current_project_id=self.project.id,
Expand Down

0 comments on commit 88e2647

Please sign in to comment.